@intlayer/backend 5.8.1 → 6.0.0-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/cjs/controllers/dictionary.controller.cjs +47 -23
  2. package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -1
  3. package/dist/cjs/controllers/eventListener.controller.cjs +2 -6
  4. package/dist/cjs/controllers/eventListener.controller.cjs.map +1 -1
  5. package/dist/cjs/controllers/project.controller.cjs.map +1 -1
  6. package/dist/cjs/controllers/user.controller.cjs +21 -4
  7. package/dist/cjs/controllers/user.controller.cjs.map +1 -1
  8. package/dist/cjs/index.cjs.map +1 -1
  9. package/dist/cjs/middlewares/oAuth2.middleware.cjs +1 -1
  10. package/dist/cjs/middlewares/oAuth2.middleware.cjs.map +1 -1
  11. package/dist/cjs/routes/dictionary.routes.cjs +9 -0
  12. package/dist/cjs/routes/dictionary.routes.cjs.map +1 -1
  13. package/dist/cjs/routes/eventListener.routes.cjs +2 -2
  14. package/dist/cjs/routes/eventListener.routes.cjs.map +1 -1
  15. package/dist/cjs/schemas/dictionary.schema.cjs +0 -5
  16. package/dist/cjs/schemas/dictionary.schema.cjs.map +1 -1
  17. package/dist/cjs/services/dictionary.service.cjs +9 -9
  18. package/dist/cjs/services/dictionary.service.cjs.map +1 -1
  19. package/dist/cjs/services/project.service.cjs.map +1 -1
  20. package/dist/cjs/services/user.service.cjs.map +1 -1
  21. package/dist/cjs/types/dictionary.types.cjs.map +1 -1
  22. package/dist/cjs/types/plan.types.cjs.map +1 -1
  23. package/dist/cjs/types/project.types.cjs.map +1 -1
  24. package/dist/cjs/utils/AI/aiSdk.cjs.map +1 -1
  25. package/dist/cjs/utils/AI/askDocQuestion/askDocQuestion.cjs +2 -1
  26. package/dist/cjs/utils/AI/askDocQuestion/askDocQuestion.cjs.map +1 -1
  27. package/dist/cjs/utils/AI/askDocQuestion/embeddings.json +91239 -47121
  28. package/dist/cjs/utils/AI/translateJSON/index.cjs +1 -1
  29. package/dist/cjs/utils/AI/translateJSON/index.cjs.map +1 -1
  30. package/dist/cjs/utils/mapper/dictionary.cjs +4 -3
  31. package/dist/cjs/utils/mapper/dictionary.cjs.map +1 -1
  32. package/dist/cjs/utils/rateLimiter.cjs +2 -2
  33. package/dist/cjs/utils/rateLimiter.cjs.map +1 -1
  34. package/dist/cjs/utils/validation/validateDictionary.cjs +2 -1
  35. package/dist/cjs/utils/validation/validateDictionary.cjs.map +1 -1
  36. package/dist/cjs/utils/validation/validateProject.cjs +2 -1
  37. package/dist/cjs/utils/validation/validateProject.cjs.map +1 -1
  38. package/dist/cjs/utils/validation/validateUser.cjs +3 -2
  39. package/dist/cjs/utils/validation/validateUser.cjs.map +1 -1
  40. package/dist/esm/controllers/dictionary.controller.mjs +46 -23
  41. package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
  42. package/dist/esm/controllers/eventListener.controller.mjs +2 -6
  43. package/dist/esm/controllers/eventListener.controller.mjs.map +1 -1
  44. package/dist/esm/controllers/project.controller.mjs.map +1 -1
  45. package/dist/esm/controllers/user.controller.mjs +21 -4
  46. package/dist/esm/controllers/user.controller.mjs.map +1 -1
  47. package/dist/esm/index.mjs.map +1 -1
  48. package/dist/esm/middlewares/oAuth2.middleware.mjs +1 -1
  49. package/dist/esm/middlewares/oAuth2.middleware.mjs.map +1 -1
  50. package/dist/esm/routes/dictionary.routes.mjs +10 -0
  51. package/dist/esm/routes/dictionary.routes.mjs.map +1 -1
  52. package/dist/esm/routes/eventListener.routes.mjs +2 -2
  53. package/dist/esm/routes/eventListener.routes.mjs.map +1 -1
  54. package/dist/esm/schemas/dictionary.schema.mjs +0 -5
  55. package/dist/esm/schemas/dictionary.schema.mjs.map +1 -1
  56. package/dist/esm/services/dictionary.service.mjs +9 -9
  57. package/dist/esm/services/dictionary.service.mjs.map +1 -1
  58. package/dist/esm/services/project.service.mjs.map +1 -1
  59. package/dist/esm/services/user.service.mjs.map +1 -1
  60. package/dist/esm/utils/AI/aiSdk.mjs.map +1 -1
  61. package/dist/esm/utils/AI/askDocQuestion/askDocQuestion.mjs +2 -1
  62. package/dist/esm/utils/AI/askDocQuestion/askDocQuestion.mjs.map +1 -1
  63. package/dist/esm/utils/AI/askDocQuestion/embeddings.json +91239 -47121
  64. package/dist/esm/utils/AI/translateJSON/index.mjs +1 -1
  65. package/dist/esm/utils/AI/translateJSON/index.mjs.map +1 -1
  66. package/dist/esm/utils/mapper/dictionary.mjs +4 -3
  67. package/dist/esm/utils/mapper/dictionary.mjs.map +1 -1
  68. package/dist/esm/utils/rateLimiter.mjs +3 -3
  69. package/dist/esm/utils/rateLimiter.mjs.map +1 -1
  70. package/dist/esm/utils/validation/validateDictionary.mjs +2 -1
  71. package/dist/esm/utils/validation/validateDictionary.mjs.map +1 -1
  72. package/dist/esm/utils/validation/validateProject.mjs +2 -1
  73. package/dist/esm/utils/validation/validateProject.mjs.map +1 -1
  74. package/dist/esm/utils/validation/validateUser.mjs +3 -2
  75. package/dist/esm/utils/validation/validateUser.mjs.map +1 -1
  76. package/dist/types/controllers/dictionary.controller.d.ts +5 -0
  77. package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
  78. package/dist/types/controllers/eventListener.controller.d.ts.map +1 -1
  79. package/dist/types/controllers/project.controller.d.ts +2 -2
  80. package/dist/types/controllers/project.controller.d.ts.map +1 -1
  81. package/dist/types/controllers/user.controller.d.ts +2 -2
  82. package/dist/types/controllers/user.controller.d.ts.map +1 -1
  83. package/dist/types/routes/dictionary.routes.d.ts +5 -0
  84. package/dist/types/routes/dictionary.routes.d.ts.map +1 -1
  85. package/dist/types/routes/eventListener.routes.d.ts +1 -3
  86. package/dist/types/routes/eventListener.routes.d.ts.map +1 -1
  87. package/dist/types/schemas/dictionary.schema.d.ts.map +1 -1
  88. package/dist/types/services/dictionary.service.d.ts +1 -1
  89. package/dist/types/services/project.service.d.ts +2 -2
  90. package/dist/types/services/project.service.d.ts.map +1 -1
  91. package/dist/types/services/user.service.d.ts +2 -2
  92. package/dist/types/services/user.service.d.ts.map +1 -1
  93. package/dist/types/types/dictionary.types.d.ts +4 -2
  94. package/dist/types/types/dictionary.types.d.ts.map +1 -1
  95. package/dist/types/types/plan.types.d.ts +2 -1
  96. package/dist/types/types/plan.types.d.ts.map +1 -1
  97. package/dist/types/types/project.types.d.ts +1 -0
  98. package/dist/types/types/project.types.d.ts.map +1 -1
  99. package/dist/types/utils/AI/aiSdk.d.ts +1 -1
  100. package/dist/types/utils/AI/aiSdk.d.ts.map +1 -1
  101. package/dist/types/utils/AI/askDocQuestion/askDocQuestion.d.ts.map +1 -1
  102. package/dist/types/utils/mapper/dictionary.d.ts +1 -2
  103. package/dist/types/utils/mapper/dictionary.d.ts.map +1 -1
  104. package/dist/types/utils/validation/validateDictionary.d.ts.map +1 -1
  105. package/dist/types/utils/validation/validateProject.d.ts +2 -2
  106. package/dist/types/utils/validation/validateProject.d.ts.map +1 -1
  107. package/dist/types/utils/validation/validateUser.d.ts +2 -2
  108. package/dist/types/utils/validation/validateUser.d.ts.map +1 -1
  109. package/package.json +30 -33
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/controllers/user.controller.ts"],"sourcesContent":["import type { User, UserAPI } from '@/types/user.types';\nimport { logger } from '@logger';\nimport type { ResponseWithSession } from '@middlewares/sessionAuth.middleware';\nimport { sendEmail } from '@services/email.service';\nimport * as userService from '@services/user.service';\nimport { type AppError, ErrorHandler } from '@utils/errors';\nimport type { FiltersAndPagination } from '@utils/filtersAndPagination/getFiltersAndPaginationFromBody';\nimport { getOrganizationFiltersAndPagination } from '@utils/filtersAndPagination/getOrganizationFiltersAndPagination';\nimport type { UserFiltersParam } from '@utils/filtersAndPagination/getUserFiltersAndPagination';\nimport { mapUsersToAPI, mapUserToAPI } from '@utils/mapper/user';\nimport { hasPermission } from '@utils/permissions';\nimport {\n formatPaginatedResponse,\n formatResponse,\n type PaginatedResponse,\n type ResponseData,\n} from '@utils/responseData';\nimport type { NextFunction, Request } from 'express';\nimport { t } from 'express-intlayer';\n\nexport type CreateUserBody = { email: string; password?: string };\nexport type CreateUserResult = ResponseData<UserAPI>;\n\n/**\n * Creates a new user.\n */\nexport const createUser = async (\n req: Request<any, any, User>,\n res: ResponseWithSession<CreateUserResult>,\n _next: NextFunction\n): Promise<void> => {\n const user: User | undefined = req.body;\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n try {\n const newUser = await userService.createUser(user);\n\n await sendEmail({\n type: 'welcome',\n to: newUser.email,\n username: newUser.name,\n loginLink: `${process.env.CLIENT_URL}/auth/login`,\n });\n\n const formattedUser = mapUserToAPI(newUser);\n\n const responseData = formatResponse<UserAPI>({\n message: t({\n en: 'User created',\n fr: 'Utilisateur créé',\n es: 'Usuario creado',\n }),\n description: t({\n en: 'User created successfully',\n fr: 'Utilisateur créé avec succès',\n es: 'Usuario creado con éxito',\n }),\n data: formattedUser,\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 GetUsersParams = FiltersAndPagination<UserFiltersParam>;\nexport type GetUsersResult = PaginatedResponse<UserAPI>;\n\n/**\n * Retrieves a list of users based on filters and pagination.\n */\nexport const getUsers = async (\n req: Request<GetUsersParams>,\n res: ResponseWithSession<GetUsersResult>,\n _next: NextFunction\n): Promise<void> => {\n const { user, roles } = res.locals;\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n const { filters, pageSize, skip, page, getNumberOfPages } =\n getOrganizationFiltersAndPagination(req);\n\n try {\n const users = await userService.findUsers(filters, skip, pageSize);\n\n if (\n !hasPermission(\n roles,\n 'user:read'\n )({\n ...res.locals,\n targetUsers: users,\n })\n ) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n const totalItems = await userService.countUsers(filters);\n\n const formattedUsers = mapUsersToAPI(users);\n\n const responseData = formatPaginatedResponse<UserAPI>({\n data: formattedUsers,\n page,\n pageSize,\n totalPages: getNumberOfPages(totalItems),\n totalItems,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type GetUserByIdParams = { userId: string };\nexport type GetUserByIdResult = ResponseData<UserAPI>;\n\nexport const getUserById = async (\n req: Request<GetUserByIdParams>,\n res: ResponseWithSession<GetUserByIdResult>,\n _next: NextFunction\n): Promise<void> => {\n const { userId } = req.params;\n\n try {\n const user = await userService.getUserById(userId);\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n const formattedUser = mapUserToAPI(user);\n const responseData = formatResponse<UserAPI>({ data: formattedUser });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type GetUserByEmailParams = { email: string };\nexport type GetUserByEmailResult = ResponseData<UserAPI>;\n\nexport const getUserByEmail = async (\n req: Request<GetUserByEmailParams>,\n res: ResponseWithSession<GetUserByEmailResult>,\n _next: NextFunction\n): Promise<void> => {\n const { email } = req.params;\n const { roles } = res.locals;\n\n try {\n const user = await userService.getUserByEmail(email);\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n if (\n !hasPermission(\n roles,\n 'user:read'\n )({\n ...res.locals,\n targetUsers: [user],\n })\n ) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n const formattedUser = mapUserToAPI(user);\n const responseData = formatResponse<UserAPI>({ data: formattedUser });\n\n res.json(responseData);\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type UpdateUserBody = Partial<User>;\nexport type UpdateUserResult = ResponseData<UserAPI>;\n\n/**\n * Updates user information (phone number, date of birth).\n */\nexport const updateUser = async (\n req: Request<any, any, UpdateUserBody | undefined>,\n res: ResponseWithSession<UpdateUserResult>,\n _next: NextFunction\n): Promise<void> => {\n const userData = req.body;\n const { user, roles } = res.locals;\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n if (typeof userData !== 'object') {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_DATA_NOT_FOUND');\n return;\n }\n\n if (\n !hasPermission(\n roles,\n 'user:write'\n )({\n ...res.locals,\n targetUsers: [userData as User],\n })\n ) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n try {\n const updatedUser = await userService.updateUserById(user.id, userData);\n\n logger.info(\n `User updated: Name: ${updatedUser.name}, id: ${String(updatedUser.id)}`\n );\n\n const formattedUser = mapUserToAPI(updatedUser);\n const responseData = formatResponse<UserAPI>({\n message: t({\n en: 'User updated',\n fr: 'Utilisateur mis à jour',\n es: 'Usuario actualizado',\n }),\n description: t({\n en: 'User updated successfully',\n fr: 'Utilisateur mis à jour avec succès',\n es: 'Usuario actualizado con éxito',\n }),\n data: formattedUser,\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 DeleteUserParams = { userId: string };\nexport type DeleteUserResult = ResponseData<UserAPI>;\n\n/**\n * Deletes a user based on the provided ID.\n */\nexport const deleteUser = async (\n req: Request<DeleteUserParams>,\n res: ResponseWithSession<DeleteUserResult>,\n _next: NextFunction\n): Promise<void> => {\n const { userId } = req.params;\n const { roles } = res.locals;\n\n try {\n const user = await userService.getUserById(userId);\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_FOUND');\n return;\n }\n\n if (\n !hasPermission(\n roles,\n 'user:admin'\n )({\n ...res.locals,\n targetUsers: [user],\n })\n ) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n await userService.deleteUser(userId);\n\n const formattedUser = mapUserToAPI(user);\n const responseData = formatResponse<UserAPI>({\n message: t({\n en: 'User deleted',\n fr: 'Utilisateur supprimé',\n es: 'Usuario eliminado',\n }),\n description: t({\n en: 'User deleted successfully',\n fr: 'Utilisateur supprimé avec succès',\n es: 'Usuario eliminado con éxito',\n }),\n data: formattedUser,\n });\n\n res.json(responseData);\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nlet clients: Array<{ id: number; userId: string; res: ResponseWithSession }> =\n [];\n\nexport const sendVerificationUpdate = (user: User) => {\n const filteredClients = clients.filter(\n (client) => String(client.userId) === String(user.id)\n );\n\n for (const client of filteredClients) {\n if (user.emailVerified) {\n client.res.write(\n `data: ${JSON.stringify({ userId: user.id, status: 'verified' })}\\n\\n`\n );\n }\n }\n};\n\nexport type VerifyEmailStatusSSEParams = { userId: string };\n\n/**\n * SSE to check the email verification status\n */\nexport const verifyEmailStatusSSE = async (\n req: Request<VerifyEmailStatusSSEParams, any, any>,\n res: ResponseWithSession\n) => {\n // Set headers for SSE\n res.setHeader('Content-Type', 'text/event-stream;charset=utf-8');\n res.setHeader('Cache-Control', 'no-cache, no-transform');\n res.setHeader('Connection', 'keep-alive');\n res.setHeader('X-Accel-Buffering', 'no'); // For Nginx buffering\n\n // Send initial data to ensure the connection is open\n res.write(':\\n\\n'); // Comment to keep connection alive\n res.flushHeaders();\n\n const { userId } = req.params; // Get user ID from query parameters\n const clientId = Date.now();\n\n const user = await userService.getUserById(userId);\n\n if (!user) {\n logger.error(`User not found - User ID: ${userId}`);\n res.write(`data: ${JSON.stringify({ userId, status: 'error' })}\\n\\n`);\n res.end();\n return;\n }\n\n // Add client to the list\n const newClient = { id: clientId, userId, res };\n clients.push(newClient);\n\n sendVerificationUpdate(user);\n\n // Remove client on connection close\n req.on('close', () => {\n clients = clients.filter((client) => client.id !== clientId);\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;A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,IACF;AAAA,EACF;AACF;AAOO,MAAM,uBAAuB,OAClC,KACA,QACG;AAEH,MAAI,UAAU,gBAAgB,iCAAiC;AAC/D,MAAI,UAAU,iBAAiB,wBAAwB;AACvD,MAAI,UAAU,cAAc,YAAY;AACxC,MAAI,UAAU,qBAAqB,IAAI;AAGvC,MAAI,MAAM,OAAO;AACjB,MAAI,aAAa;AAEjB,QAAM,EAAE,OAAO,IAAI,IAAI;AACvB,QAAM,WAAW,KAAK,IAAI;AAE1B,QAAM,OAAO,MAAM,YAAY,YAAY,MAAM;AAEjD,MAAI,CAAC,MAAM;AACT,yBAAO,MAAM,6BAA6B,MAAM,EAAE;AAClD,QAAI,MAAM,SAAS,KAAK,UAAU,EAAE,QAAQ,QAAQ,QAAQ,CAAC,CAAC;AAAA;AAAA,CAAM;AACpE,QAAI,IAAI;AACR;AAAA,EACF;AAGA,QAAM,YAAY,EAAE,IAAI,UAAU,QAAQ,IAAI;AAC9C,UAAQ,KAAK,SAAS;AAEtB,yBAAuB,IAAI;AAG3B,MAAI,GAAG,SAAS,MAAM;AACpB,cAAU,QAAQ,OAAO,CAAC,WAAW,OAAO,OAAO,QAAQ;AAAA,EAC7D,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/controllers/user.controller.ts"],"sourcesContent":["import type { User, UserAPI } from '@/types/user.types';\nimport { logger } from '@logger';\nimport type { ResponseWithSession } from '@middlewares/sessionAuth.middleware';\nimport { sendEmail } from '@services/email.service';\nimport * as userService from '@services/user.service';\nimport { type AppError, ErrorHandler } from '@utils/errors';\nimport type { FiltersAndPagination } from '@utils/filtersAndPagination/getFiltersAndPaginationFromBody';\nimport { getOrganizationFiltersAndPagination } from '@utils/filtersAndPagination/getOrganizationFiltersAndPagination';\nimport type { UserFiltersParam } from '@utils/filtersAndPagination/getUserFiltersAndPagination';\nimport { mapUsersToAPI, mapUserToAPI } from '@utils/mapper/user';\nimport { hasPermission } from '@utils/permissions';\nimport {\n formatPaginatedResponse,\n formatResponse,\n type PaginatedResponse,\n type ResponseData,\n} from '@utils/responseData';\nimport type { NextFunction, Request } from 'express';\nimport { t } from 'express-intlayer';\n\nexport type CreateUserBody = { email: string; password?: string };\nexport type CreateUserResult = ResponseData<UserAPI>;\n\n/**\n * Creates a new user.\n */\nexport const createUser = async (\n req: Request<any, any, User>,\n res: ResponseWithSession<CreateUserResult>,\n _next: NextFunction\n): Promise<void> => {\n const user: User | undefined = req.body;\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n try {\n const newUser = await userService.createUser(user);\n\n await sendEmail({\n type: 'welcome',\n to: newUser.email,\n username: newUser.name,\n loginLink: `${process.env.CLIENT_URL}/auth/login`,\n });\n\n const formattedUser = mapUserToAPI(newUser);\n\n const responseData = formatResponse<UserAPI>({\n message: t({\n en: 'User created',\n fr: 'Utilisateur créé',\n es: 'Usuario creado',\n }),\n description: t({\n en: 'User created successfully',\n fr: 'Utilisateur créé avec succès',\n es: 'Usuario creado con éxito',\n }),\n data: formattedUser,\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 GetUsersParams = FiltersAndPagination<UserFiltersParam>;\nexport type GetUsersResult = PaginatedResponse<UserAPI>;\n\n/**\n * Retrieves a list of users based on filters and pagination.\n */\nexport const getUsers = async (\n req: Request<GetUsersParams>,\n res: ResponseWithSession<GetUsersResult>,\n _next: NextFunction\n): Promise<void> => {\n const { user, organization, roles } = res.locals;\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n if (!organization) {\n ErrorHandler.handleGenericErrorResponse(res, 'ORGANIZATION_NOT_DEFINED');\n return;\n }\n\n const { filters, pageSize, skip, page, getNumberOfPages } =\n getOrganizationFiltersAndPagination(req);\n\n try {\n const users = await userService.findUsers(\n { $and: [filters, { _id: { $in: organization.membersIds } }] },\n skip,\n pageSize\n );\n\n if (\n !hasPermission(\n roles,\n 'user:read'\n )({\n ...res.locals,\n targetUsers: users,\n })\n ) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n const totalItems = await userService.countUsers(filters);\n\n const formattedUsers = mapUsersToAPI(users);\n\n const responseData = formatPaginatedResponse<UserAPI>({\n data: formattedUsers,\n page,\n pageSize,\n totalPages: getNumberOfPages(totalItems),\n totalItems,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type GetUserByIdParams = { userId: UserAPI['id'] };\nexport type GetUserByIdResult = ResponseData<UserAPI>;\n\nexport const getUserById = async (\n req: Request<GetUserByIdParams>,\n res: ResponseWithSession<GetUserByIdResult>,\n _next: NextFunction\n): Promise<void> => {\n const { userId } = req.params;\n\n try {\n const user = await userService.getUserById(userId);\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n const formattedUser = mapUserToAPI(user);\n const responseData = formatResponse<UserAPI>({ data: formattedUser });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type GetUserByEmailParams = { email: string };\nexport type GetUserByEmailResult = ResponseData<UserAPI>;\n\nexport const getUserByEmail = async (\n req: Request<GetUserByEmailParams>,\n res: ResponseWithSession<GetUserByEmailResult>,\n _next: NextFunction\n): Promise<void> => {\n const { email } = req.params;\n const { roles } = res.locals;\n\n try {\n const user = await userService.getUserByEmail(email);\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n if (\n !hasPermission(\n roles,\n 'user:read'\n )({\n ...res.locals,\n targetUsers: [user],\n })\n ) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n const formattedUser = mapUserToAPI(user);\n const responseData = formatResponse<UserAPI>({ data: formattedUser });\n\n res.json(responseData);\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type UpdateUserBody = Partial<UserAPI>;\nexport type UpdateUserResult = ResponseData<UserAPI>;\n\n/**\n * Updates user information (phone number, date of birth).\n */\nexport const updateUser = async (\n req: Request<any, any, UpdateUserBody | undefined>,\n res: ResponseWithSession<UpdateUserResult>,\n _next: NextFunction\n): Promise<void> => {\n const userData = req.body;\n const { user, roles } = res.locals;\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n if (typeof userData !== 'object') {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_DATA_NOT_FOUND');\n return;\n }\n\n if (!userData.id) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_INVALID_FIELDS');\n return;\n }\n\n const userDB = await userService.getUserById(userData.id);\n\n if (!userDB) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_FOUND');\n return;\n }\n\n if (\n !hasPermission(\n roles,\n 'user:write'\n )({\n ...res.locals,\n targetUsers: [userDB],\n })\n ) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n try {\n const updatedUser = await userService.updateUserById(userDB.id, userData);\n\n logger.info(\n `User updated: Name: ${updatedUser.name}, id: ${String(updatedUser.id)}`\n );\n\n const formattedUser = mapUserToAPI(updatedUser);\n const responseData = formatResponse<UserAPI>({\n message: t({\n en: 'User updated',\n fr: 'Utilisateur mis à jour',\n es: 'Usuario actualizado',\n }),\n description: t({\n en: 'User updated successfully',\n fr: 'Utilisateur mis à jour avec succès',\n es: 'Usuario actualizado con éxito',\n }),\n data: formattedUser,\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 DeleteUserParams = { userId: string };\nexport type DeleteUserResult = ResponseData<UserAPI>;\n\n/**\n * Deletes a user based on the provided ID.\n */\nexport const deleteUser = async (\n req: Request<DeleteUserParams>,\n res: ResponseWithSession<DeleteUserResult>,\n _next: NextFunction\n): Promise<void> => {\n const { userId } = req.params;\n const { roles } = res.locals;\n\n try {\n const user = await userService.getUserById(userId);\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_FOUND');\n return;\n }\n\n if (\n !hasPermission(\n roles,\n 'user:admin'\n )({\n ...res.locals,\n targetUsers: [user],\n })\n ) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n await userService.deleteUser(userId);\n\n const formattedUser = mapUserToAPI(user);\n const responseData = formatResponse<UserAPI>({\n message: t({\n en: 'User deleted',\n fr: 'Utilisateur supprimé',\n es: 'Usuario eliminado',\n }),\n description: t({\n en: 'User deleted successfully',\n fr: 'Utilisateur supprimé avec succès',\n es: 'Usuario eliminado con éxito',\n }),\n data: formattedUser,\n });\n\n res.json(responseData);\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nlet clients: Array<{ id: number; userId: string; res: ResponseWithSession }> =\n [];\n\nexport const sendVerificationUpdate = (user: User) => {\n const filteredClients = clients.filter(\n (client) => String(client.userId) === String(user.id)\n );\n\n for (const client of filteredClients) {\n if (user.emailVerified) {\n client.res.write(\n `data: ${JSON.stringify({ userId: user.id, status: 'verified' })}\\n\\n`\n );\n }\n }\n};\n\nexport type VerifyEmailStatusSSEParams = { userId: string };\n\n/**\n * SSE to check the email verification status\n */\nexport const verifyEmailStatusSSE = async (\n req: Request<VerifyEmailStatusSSEParams, any, any>,\n res: ResponseWithSession\n) => {\n // Set headers for SSE\n res.setHeader('Content-Type', 'text/event-stream;charset=utf-8');\n res.setHeader('Cache-Control', 'no-cache, no-transform');\n res.setHeader('Connection', 'keep-alive');\n res.setHeader('X-Accel-Buffering', 'no'); // For Nginx buffering\n\n // Send initial data to ensure the connection is open\n res.write(':\\n\\n'); // Comment to keep connection alive\n res.flushHeaders();\n\n const { userId } = req.params; // Get user ID from query parameters\n const clientId = Date.now();\n\n const user = await userService.getUserById(userId);\n\n if (!user) {\n logger.error(`User not found - User ID: ${userId}`);\n res.write(`data: ${JSON.stringify({ userId, status: 'error' })}\\n\\n`);\n res.end();\n return;\n }\n\n // Add client to the list\n const newClient = { id: clientId, userId, res };\n clients.push(newClient);\n\n sendVerificationUpdate(user);\n\n // Remove client on connection close\n req.on('close', () => {\n clients = clients.filter((client) => client.id !== clientId);\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAuB;AAEvB,mBAA0B;AAC1B,kBAA6B;AAC7B,oBAA4C;AAE5C,iDAAoD;AAEpD,kBAA4C;AAC5C,yBAA8B;AAC9B,0BAKO;AAEP,8BAAkB;AAQX,MAAM,aAAa,OACxB,KACA,KACA,UACkB;AAClB,QAAM,OAAyB,IAAI;AAEnC,MAAI,CAAC,MAAM;AACT,+BAAa,2BAA2B,KAAK,kBAAkB;AAC/D;AAAA,EACF;AAEA,MAAI;AACF,UAAM,UAAU,MAAM,YAAY,WAAW,IAAI;AAEjD,cAAM,wBAAU;AAAA,MACd,MAAM;AAAA,MACN,IAAI,QAAQ;AAAA,MACZ,UAAU,QAAQ;AAAA,MAClB,WAAW,GAAG,QAAQ,IAAI,UAAU;AAAA,IACtC,CAAC;AAED,UAAM,oBAAgB,0BAAa,OAAO;AAE1C,UAAM,mBAAe,oCAAwB;AAAA,MAC3C,aAAS,2BAAE;AAAA,QACT,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN,CAAC;AAAA,MACD,iBAAa,2BAAE;AAAA,QACb,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN,CAAC;AAAA,MACD,MAAM;AAAA,IACR,CAAC;AAED,QAAI,KAAK,YAAY;AACrB;AAAA,EACF,SAAS,OA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;AAAA;AAAA,CAAM;AACpE,QAAI,IAAI;AACR;AAAA,EACF;AAGA,QAAM,YAAY,EAAE,IAAI,UAAU,QAAQ,IAAI;AAC9C,UAAQ,KAAK,SAAS;AAEtB,yBAAuB,IAAI;AAG3B,MAAI,GAAG,SAAS,MAAM;AACpB,cAAU,QAAQ,OAAO,CAAC,WAAW,OAAO,OAAO,QAAQ;AAAA,EAC7D,CAAC;AACH;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// Libraries\nimport { toNodeHandler } from 'better-auth/node';\nimport compression from 'compression';\nimport cookieParser from 'cookie-parser';\nimport cors from 'cors';\nimport dotenv from 'dotenv';\nimport express, { type Express } from 'express';\nimport { intlayer, t } from 'express-intlayer';\nimport helmet from 'helmet';\n\n// Middlewares\nimport { getOAuth2AccessToken } from '@controllers/oAuth2.controller';\nimport {\n attachOAuthInstance,\n oAuth2Middleware,\n} from '@middlewares/oAuth2.middleware';\nimport { logAPIRequestURL } from '@middlewares/request.middleware';\n\n// Services\n\n// Routes\nimport { aiRoute, aiRouter } from '@routes/ai.routes';\nimport { dictionaryRoute, dictionaryRouter } from '@routes/dictionary.routes';\nimport {\n eventListenerRoute,\n eventListenerRouter,\n} from '@routes/eventListener.routes';\nimport { newsletterRoute, newsletterRouter } from '@routes/newsletter.routes';\nimport {\n organizationRoute,\n organizationRouter,\n} from '@routes/organization.routes';\nimport { projectRoute, projectRouter } from '@routes/project.routes';\nimport { searchRoute, searchRouter } from '@routes/search.routes';\nimport { stripeRoute, stripeRouter } from '@routes/stripe.routes';\nimport { tagRoute, tagRouter } from '@routes/tags.routes';\nimport { userRoute, userRouter } from '@routes/user.routes';\n\n// Webhooks\nimport { stripeWebhook } from '@webhooks/stripe.webhook';\n\n// Utils\nimport { getAuth } from '@utils/auth/getAuth';\nimport { connectDB } from '@utils/mongoDB/connectDB';\nimport { ipLimiter } from '@utils/rateLimiter';\n\n// Logger\nimport { authMiddleware } from '@middlewares/sessionAuth.middleware';\nimport { corsOptions } from '@utils/cors';\nimport { logger } from './logger/index';\n\nconst startServer = async () => {\n const app: Express = express();\n\n // Headers security\n app.disable('x-powered-by'); // Disabled to prevent attackers from knowing that the app is running Express\n app.use(helmet());\n app.set('trust proxy', 1);\n\n // Environment variables\n const env = app.get('env');\n\n logger.info(`run as ${env}`);\n\n dotenv.config({\n path: [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env'],\n });\n\n // Parse incoming requests with cookies\n app.use(cookieParser());\n\n // Load internationalization request handler\n app.use(intlayer());\n\n // Rate limiter\n app.use(/(.*)/, ipLimiter);\n\n // Connect to MongoDB\n const dbClient = await connectDB();\n\n // Stripe\n app.post(\n '/webhook/stripe',\n express.raw({ type: 'application/json' }),\n stripeWebhook\n );\n\n // Compress all HTTP responses\n app.use(compression());\n\n // Parse incoming requests with urlencoded payloads\n app.use(express.urlencoded({ extended: true }));\n\n // CORS\n app.use(cors(corsOptions));\n\n // Liveness check\n app.get('/', (_req, res) => {\n res.send(\n t({\n en: 'Ok - locale: en',\n fr: 'Ok - locale: fr',\n es: 'Ok - locale: es',\n })\n );\n });\n\n // Session Auth\n const auth = getAuth(dbClient);\n app.all('/api/auth/{*any}', toNodeHandler(auth));\n app.use(/(.*)/, authMiddleware(auth));\n\n // oAuth2 Auth\n app.use(/(.*)/, attachOAuthInstance);\n app.post('/oauth2/token', getOAuth2AccessToken); // Route to get the token\n app.use(/(.*)/, oAuth2Middleware);\n\n // Body parser\n app.use(express.json()); // Should be placed after auth. Attach body to next routes\n\n // debug\n const isDev = env === 'development';\n if (isDev) {\n app.use(logAPIRequestURL);\n }\n\n // Routes\n app.use(userRoute, userRouter);\n app.use(organizationRoute, organizationRouter);\n app.use(projectRoute, projectRouter);\n app.use(tagRoute, tagRouter);\n app.use(dictionaryRoute, dictionaryRouter);\n app.use(stripeRoute, stripeRouter);\n app.use(aiRoute, aiRouter);\n app.use(eventListenerRoute, eventListenerRouter);\n app.use(searchRoute, searchRouter);\n app.use(newsletterRoute, newsletterRouter);\n\n // Server\n app.listen(process.env.PORT, () => {\n logger.info(`Listening on port ${process.env.PORT}`);\n });\n};\n\nstartServer();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,kBAA8B;AAC9B,yBAAwB;AACxB,2BAAyB;AACzB,kBAAiB;AACjB,oBAAmB;AACnB,qBAAsC;AACtC,8BAA4B;AAC5B,oBAAmB;AAGnB,oBAAqC;AACrC,IAAAA,iBAGO;AACP,qBAAiC;AAKjC,gBAAkC;AAClC,wBAAkD;AAClD,2BAGO;AACP,wBAAkD;AAClD,0BAGO;AACP,qBAA4C;AAC5C,oBAA0C;AAC1C,oBAA0C;AAC1C,kBAAoC;AACpC,kBAAsC;AAGtC,IAAAC,iBAA8B;AAG9B,qBAAwB;AACxB,uBAA0B;AAC1B,yBAA0B;AAG1B,yBAA+B;AAC/B,IAAAC,eAA4B;AAC5B,oBAAuB;AAEvB,MAAM,cAAc,YAAY;AAC9B,QAAM,UAAe,eAAAC,SAAQ;AAG7B,MAAI,QAAQ,cAAc;AAC1B,MAAI,QAAI,cAAAC,SAAO,CAAC;AAChB,MAAI,IAAI,eAAe,CAAC;AAGxB,QAAM,MAAM,IAAI,IAAI,KAAK;AAEzB,uBAAO,KAAK,UAAU,GAAG,EAAE;AAE3B,gBAAAC,QAAO,OAAO;AAAA,IACZ,MAAM,CAAC,QAAQ,GAAG,UAAU,QAAQ,GAAG,IAAI,cAAc,MAAM;AAAA,EACjE,CAAC;AAGD,MAAI,QAAI,qBAAAC,SAAa,CAAC;AAGtB,MAAI,QAAI,kCAAS,CAAC;AAGlB,MAAI,IAAI,QAAQ,4BAAS;AAGzB,QAAM,WAAW,UAAM,4BAAU;AAGjC,MAAI;AAAA,IACF;AAAA,IACA,eAAAH,QAAQ,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAAA,IACxC;AAAA,EACF;AAGA,MAAI,QAAI,mBAAAI,SAAY,CAAC;AAGrB,MAAI,IAAI,eAAAJ,QAAQ,WAAW,EAAE,UAAU,KAAK,CAAC,CAAC;AAG9C,MAAI,QAAI,YAAAK,SAAK,wBAAW,CAAC;AAGzB,MAAI,IAAI,KAAK,CAAC,MAAM,QAAQ;AAC1B,QAAI;AAAA,UACF,2BAAE;AAAA,QACA,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAGD,QAAM,WAAO,wBAAQ,QAAQ;AAC7B,MAAI,IAAI,wBAAoB,2BAAc,IAAI,CAAC;AAC/C,MAAI,IAAI,YAAQ,mCAAe,IAAI,CAAC;AAGpC,MAAI,IAAI,QAAQ,kCAAmB;AACnC,MAAI,KAAK,iBAAiB,kCAAoB;AAC9C,MAAI,IAAI,QAAQ,+BAAgB;AAGhC,MAAI,IAAI,eAAAL,QAAQ,KAAK,CAAC;AAGtB,QAAM,QAAQ,QAAQ;AACtB,MAAI,OAAO;AACT,QAAI,IAAI,+BAAgB;AAAA,EAC1B;AAGA,MAAI,IAAI,uBAAW,sBAAU;AAC7B,MAAI,IAAI,uCAAmB,sCAAkB;AAC7C,MAAI,IAAI,6BAAc,4BAAa;AACnC,MAAI,IAAI,sBAAU,qBAAS;AAC3B,MAAI,IAAI,mCAAiB,kCAAgB;AACzC,MAAI,IAAI,2BAAa,0BAAY;AACjC,MAAI,IAAI,mBAAS,kBAAQ;AACzB,MAAI,IAAI,yCAAoB,wCAAmB;AAC/C,MAAI,IAAI,2BAAa,0BAAY;AACjC,MAAI,IAAI,mCAAiB,kCAAgB;AAGzC,MAAI,OAAO,QAAQ,IAAI,MAAM,MAAM;AACjC,yBAAO,KAAK,qBAAqB,QAAQ,IAAI,IAAI,EAAE;AAAA,EACrD,CAAC;AACH;AAEA,YAAY;","names":["import_oAuth2","import_stripe","import_cors","express","helmet","dotenv","cookieParser","compression","cors"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// Libraries\nimport { toNodeHandler } from 'better-auth/node';\nimport compression from 'compression';\nimport cookieParser from 'cookie-parser';\nimport cors from 'cors';\nimport dotenv from 'dotenv';\nimport express, { type Express } from 'express';\nimport { intlayer, t } from 'express-intlayer';\nimport helmet from 'helmet';\n\n// Middlewares\nimport { getOAuth2AccessToken } from '@controllers/oAuth2.controller';\nimport {\n attachOAuthInstance,\n oAuth2Middleware,\n} from '@middlewares/oAuth2.middleware';\nimport { logAPIRequestURL } from '@middlewares/request.middleware';\n\n// Services\n\n// Routes\nimport { aiRoute, aiRouter } from '@routes/ai.routes';\nimport { dictionaryRoute, dictionaryRouter } from '@routes/dictionary.routes';\nimport {\n eventListenerRoute,\n eventListenerRouter,\n} from '@routes/eventListener.routes';\nimport { newsletterRoute, newsletterRouter } from '@routes/newsletter.routes';\nimport {\n organizationRoute,\n organizationRouter,\n} from '@routes/organization.routes';\nimport { projectRoute, projectRouter } from '@routes/project.routes';\nimport { searchRoute, searchRouter } from '@routes/search.routes';\nimport { stripeRoute, stripeRouter } from '@routes/stripe.routes';\nimport { tagRoute, tagRouter } from '@routes/tags.routes';\nimport { userRoute, userRouter } from '@routes/user.routes';\n\n// Webhooks\nimport { stripeWebhook } from '@webhooks/stripe.webhook';\n\n// Utils\nimport { getAuth } from '@utils/auth/getAuth';\nimport { connectDB } from '@utils/mongoDB/connectDB';\nimport { ipLimiter } from '@utils/rateLimiter';\n\n// Logger\nimport { authMiddleware } from '@middlewares/sessionAuth.middleware';\nimport { corsOptions } from '@utils/cors';\nimport { logger } from './logger/index';\n\nconst startServer = async () => {\n const app: Express = express();\n\n // Headers security\n app.disable('x-powered-by'); // Disabled to prevent attackers from knowing that the app is running Express\n app.use(helmet());\n app.set('trust proxy', 1);\n\n // Environment variables\n const env = app.get('env');\n\n logger.info(`run as ${env}`);\n\n dotenv.config({\n path: [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env'],\n });\n\n // Parse incoming requests with cookies\n app.use(cookieParser());\n\n // Load internationalization request handler\n app.use(intlayer());\n\n // Rate limiter\n app.use(/(.*)/, ipLimiter);\n\n // Connect to MongoDB\n const dbClient = await connectDB();\n\n // Stripe\n app.post(\n '/webhook/stripe',\n express.raw({ type: 'application/json' }),\n stripeWebhook\n );\n\n // Compress all HTTP responses\n app.use(compression());\n\n // Parse incoming requests with urlencoded payloads\n app.use(express.urlencoded({ extended: true }));\n\n // CORS\n app.use(cors(corsOptions));\n\n // Liveness check\n app.get('/', (_req, res) => {\n res.send(\n t({\n en: 'Ok - locale: en',\n fr: 'Ok - locale: fr',\n es: 'Ok - locale: es',\n })\n );\n });\n\n // Session Auth\n const auth = getAuth(dbClient as any);\n app.all('/api/auth/{*any}', toNodeHandler(auth));\n app.use(/(.*)/, authMiddleware(auth));\n\n // oAuth2 Auth\n app.use(/(.*)/, attachOAuthInstance);\n app.post('/oauth2/token', getOAuth2AccessToken); // Route to get the token\n app.use(/(.*)/, oAuth2Middleware);\n\n // Body parser\n app.use(express.json()); // Should be placed after auth. Attach body to next routes\n\n // debug\n const isDev = env === 'development';\n if (isDev) {\n app.use(logAPIRequestURL);\n }\n\n // Routes\n app.use(userRoute, userRouter);\n app.use(organizationRoute, organizationRouter);\n app.use(projectRoute, projectRouter);\n app.use(tagRoute, tagRouter);\n app.use(dictionaryRoute, dictionaryRouter);\n app.use(stripeRoute, stripeRouter);\n app.use(aiRoute, aiRouter);\n app.use(eventListenerRoute, eventListenerRouter);\n app.use(searchRoute, searchRouter);\n app.use(newsletterRoute, newsletterRouter);\n\n // Server\n app.listen(process.env.PORT, () => {\n logger.info(`Listening on port ${process.env.PORT}`);\n });\n};\n\nstartServer();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,kBAA8B;AAC9B,yBAAwB;AACxB,2BAAyB;AACzB,kBAAiB;AACjB,oBAAmB;AACnB,qBAAsC;AACtC,8BAA4B;AAC5B,oBAAmB;AAGnB,oBAAqC;AACrC,IAAAA,iBAGO;AACP,qBAAiC;AAKjC,gBAAkC;AAClC,wBAAkD;AAClD,2BAGO;AACP,wBAA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AAQ,mCAAe,IAAI,CAAC;AAGpC,MAAI,IAAI,QAAQ,kCAAmB;AACnC,MAAI,KAAK,iBAAiB,kCAAoB;AAC9C,MAAI,IAAI,QAAQ,+BAAgB;AAGhC,MAAI,IAAI,eAAAL,QAAQ,KAAK,CAAC;AAGtB,QAAM,QAAQ,QAAQ;AACtB,MAAI,OAAO;AACT,QAAI,IAAI,+BAAgB;AAAA,EAC1B;AAGA,MAAI,IAAI,uBAAW,sBAAU;AAC7B,MAAI,IAAI,uCAAmB,sCAAkB;AAC7C,MAAI,IAAI,6BAAc,4BAAa;AACnC,MAAI,IAAI,sBAAU,qBAAS;AAC3B,MAAI,IAAI,mCAAiB,kCAAgB;AACzC,MAAI,IAAI,2BAAa,0BAAY;AACjC,MAAI,IAAI,mBAAS,kBAAQ;AACzB,MAAI,IAAI,yCAAoB,wCAAmB;AAC/C,MAAI,IAAI,2BAAa,0BAAY;AACjC,MAAI,IAAI,mCAAiB,kCAAgB;AAGzC,MAAI,OAAO,QAAQ,IAAI,MAAM,MAAM;AACjC,yBAAO,KAAK,qBAAqB,QAAQ,IAAI,IAAI,EAAE;AAAA,EACrD,CAAC;AACH;AAEA,YAAY;","names":["import_oAuth2","import_stripe","import_cors","express","helmet","dotenv","cookieParser","compression","cors"]}
@@ -53,7 +53,7 @@ const oAuth2Middleware = async (req, res, next) => {
53
53
  return next();
54
54
  }
55
55
  try {
56
- const hasToken = !!req.headers.authorization;
56
+ const hasToken = Boolean(req.headers.authorization);
57
57
  if (!hasToken) {
58
58
  return next();
59
59
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middlewares/oAuth2.middleware.ts"],"sourcesContent":["import { logger } from '@logger';\nimport {\n getOAuth2AccessTokenContext,\n validateOAuth2AccessToken,\n} from '@services/oAuth2.service';\nimport { formatSession } from '@utils/auth/getAuth';\nimport { AppError, ErrorHandler } from '@utils/errors';\nimport { authenticateOptions, getAuthModel } from '@utils/oAuth2';\nimport type { NextFunction, Request, Response } from 'express';\nimport OAuth2Server, {\n Request as OAuthRequest,\n Response as OAuthResponse,\n} from 'oauth2-server';\n\n// Configuration of the OAuth server\nconst oauth = new OAuth2Server({\n model: getAuthModel(),\n accessTokenLifetime: 60 * 60, // 1 hour\n allowBearerTokensInQueryString: true,\n});\n\nexport type RequestWithOAuth2Information<\n P = any,\n ResBody = any,\n ReqBody = any,\n ReqQuery = qs.ParsedQs,\n> = Request<P, ResBody, ReqBody, ReqQuery> & {\n oauth: OAuth2Server;\n};\n\nexport const attachOAuthInstance = async (\n req: Request,\n _res: Response,\n next: NextFunction\n) => {\n // Attach the instance OAuth to the requests\n (req as RequestWithOAuth2Information).oauth = oauth;\n\n next();\n};\n\n// Middleware to authenticate requests\nexport const oAuth2Middleware = async (\n req: Request,\n res: Response,\n next: NextFunction\n): Promise<void> => {\n if (typeof res.locals.authType !== 'undefined') {\n // Skip if user is already authenticated (ex: session)\n return next();\n }\n\n try {\n const hasToken = !!req.headers.authorization;\n\n if (!hasToken) {\n // If the request does not have a token, skip the oAuth2 authentication\n // Necessary because the oAuth2 library will throw an error if the token is not present\n return next();\n }\n\n // Authenticate the request using OAuth2\n const oauthRequest = new OAuthRequest(req);\n\n const oauthResponse = new OAuthResponse(res);\n\n const oAuthToken = await (\n req as RequestWithOAuth2Information\n ).oauth.authenticate(oauthRequest, oauthResponse, authenticateOptions);\n\n const validatedToken = await validateOAuth2AccessToken(\n oAuthToken.accessToken\n );\n\n const result = await getOAuth2AccessTokenContext(validatedToken);\n\n const formattedSession = formatSession(result);\n res.locals.authType = 'session';\n\n // Attach the session to the response locals\n Object.entries(formattedSession).forEach(([key, value]) => {\n (res.locals as any)[key] = value;\n });\n\n logger.info(\n 'OAuth2 bearer token authenticated',\n formattedSession.user.email\n );\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n\n return;\n }\n\n next();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AACvB,oBAGO;AACP,qBAA8B;AAC9B,oBAAuC;AACvC,IAAAA,iBAAkD;AAElD,2BAGO;AAGP,MAAM,QAAQ,IAAI,qBAAAC,QAAa;AAAA,EAC7B,WAAO,6BAAa;AAAA,EACpB,qBAAqB,KAAK;AAAA;AAAA,EAC1B,gCAAgC;AAClC,CAAC;AAWM,MAAM,sBAAsB,OACjC,KACA,MACA,SACG;AAEH,EAAC,IAAqC,QAAQ;AAE9C,OAAK;AACP;AAGO,MAAM,mBAAmB,OAC9B,KACA,KACA,SACkB;AAClB,MAAI,OAAO,IAAI,OAAO,aAAa,aAAa;AAE9C,WAAO,KAAK;AAAA,EACd;AAEA,MAAI;AACF,UAAM,WAAW,CAAC,CAAC,IAAI,QAAQ;AAE/B,QAAI,CAAC,UAAU;AAGb,aAAO,KAAK;AAAA,IACd;AAGA,UAAM,eAAe,IAAI,qBAAAC,QAAa,GAAG;AAEzC,UAAM,gBAAgB,IAAI,qBAAAC,SAAc,GAAG;AAE3C,UAAM,aAAa,MACjB,IACA,MAAM,aAAa,cAAc,eAAe,kCAAmB;AAErE,UAAM,iBAAiB,UAAM;AAAA,MAC3B,WAAW;AAAA,IACb;AAEA,UAAM,SAAS,UAAM,2CAA4B,cAAc;AAE/D,UAAM,uBAAmB,8BAAc,MAAM;AAC7C,QAAI,OAAO,WAAW;AAGtB,WAAO,QAAQ,gBAAgB,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACzD,MAAC,IAAI,OAAe,GAAG,IAAI;AAAA,IAC7B,CAAC;AAED,yBAAO;AAAA,MACL;AAAA,MACA,iBAAiB,KAAK;AAAA,IACxB;AAAA,EACF,SAAS,OAAO;AACd,+BAAa,uBAAuB,KAAK,KAAiB;AAE1D;AAAA,EACF;AAEA,OAAK;AACP;","names":["import_oAuth2","OAuth2Server","OAuthRequest","OAuthResponse"]}
1
+ {"version":3,"sources":["../../../src/middlewares/oAuth2.middleware.ts"],"sourcesContent":["import { logger } from '@logger';\nimport {\n getOAuth2AccessTokenContext,\n validateOAuth2AccessToken,\n} from '@services/oAuth2.service';\nimport { formatSession } from '@utils/auth/getAuth';\nimport { AppError, ErrorHandler } from '@utils/errors';\nimport { authenticateOptions, getAuthModel } from '@utils/oAuth2';\nimport type { NextFunction, Request, Response } from 'express';\nimport OAuth2Server, {\n Request as OAuthRequest,\n Response as OAuthResponse,\n} from 'oauth2-server';\n\n// Configuration of the OAuth server\nconst oauth = new OAuth2Server({\n model: getAuthModel(),\n accessTokenLifetime: 60 * 60, // 1 hour\n allowBearerTokensInQueryString: true,\n});\n\nexport type RequestWithOAuth2Information<\n P = any,\n ResBody = any,\n ReqBody = any,\n ReqQuery = qs.ParsedQs,\n> = Request<P, ResBody, ReqBody, ReqQuery> & {\n oauth: OAuth2Server;\n};\n\nexport const attachOAuthInstance = async (\n req: Request,\n _res: Response,\n next: NextFunction\n) => {\n // Attach the instance OAuth to the requests\n (req as RequestWithOAuth2Information).oauth = oauth;\n\n next();\n};\n\n// Middleware to authenticate requests\nexport const oAuth2Middleware = async (\n req: Request,\n res: Response,\n next: NextFunction\n): Promise<void> => {\n if (typeof res.locals.authType !== 'undefined') {\n // Skip if user is already authenticated (ex: session)\n return next();\n }\n\n try {\n const hasToken = Boolean(req.headers.authorization);\n\n if (!hasToken) {\n // If the request does not have a token, skip the oAuth2 authentication\n // Necessary because the oAuth2 library will throw an error if the token is not present\n return next();\n }\n\n // Authenticate the request using OAuth2\n const oauthRequest = new OAuthRequest(req);\n\n const oauthResponse = new OAuthResponse(res);\n\n const oAuthToken = await (\n req as RequestWithOAuth2Information\n ).oauth.authenticate(oauthRequest, oauthResponse, authenticateOptions);\n\n const validatedToken = await validateOAuth2AccessToken(\n oAuthToken.accessToken\n );\n\n const result = await getOAuth2AccessTokenContext(validatedToken);\n\n const formattedSession = formatSession(result);\n res.locals.authType = 'session';\n\n // Attach the session to the response locals\n Object.entries(formattedSession).forEach(([key, value]) => {\n (res.locals as any)[key] = value;\n });\n\n logger.info(\n 'OAuth2 bearer token authenticated',\n formattedSession.user.email\n );\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n\n return;\n }\n\n next();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AACvB,oBAGO;AACP,qBAA8B;AAC9B,oBAAuC;AACvC,IAAAA,iBAAkD;AAElD,2BAGO;AAGP,MAAM,QAAQ,IAAI,qBAAAC,QAAa;AAAA,EAC7B,WAAO,6BAAa;AAAA,EACpB,qBAAqB,KAAK;AAAA;AAAA,EAC1B,gCAAgC;AAClC,CAAC;AAWM,MAAM,sBAAsB,OACjC,KACA,MACA,SACG;AAEH,EAAC,IAAqC,QAAQ;AAE9C,OAAK;AACP;AAGO,MAAM,mBAAmB,OAC9B,KACA,KACA,SACkB;AAClB,MAAI,OAAO,IAAI,OAAO,aAAa,aAAa;AAE9C,WAAO,KAAK;AAAA,EACd;AAEA,MAAI;AACF,UAAM,WAAW,QAAQ,IAAI,QAAQ,aAAa;AAElD,QAAI,CAAC,UAAU;AAGb,aAAO,KAAK;AAAA,IACd;AAGA,UAAM,eAAe,IAAI,qBAAAC,QAAa,GAAG;AAEzC,UAAM,gBAAgB,IAAI,qBAAAC,SAAc,GAAG;AAE3C,UAAM,aAAa,MACjB,IACA,MAAM,aAAa,cAAc,eAAe,kCAAmB;AAErE,UAAM,iBAAiB,UAAM;AAAA,MAC3B,WAAW;AAAA,IACb;AAEA,UAAM,SAAS,UAAM,2CAA4B,cAAc;AAE/D,UAAM,uBAAmB,8BAAc,MAAM;AAC7C,QAAI,OAAO,WAAW;AAGtB,WAAO,QAAQ,gBAAgB,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACzD,MAAC,IAAI,OAAe,GAAG,IAAI;AAAA,IAC7B,CAAC;AAED,yBAAO;AAAA,MACL;AAAA,MACA,iBAAiB,KAAK;AAAA,IACxB;AAAA,EACF,SAAS,OAAO;AACd,+BAAa,uBAAuB,KAAK,KAAiB;AAE1D;AAAA,EACF;AAEA,OAAK;AACP;","names":["import_oAuth2","OAuth2Server","OAuthRequest","OAuthResponse"]}
@@ -39,6 +39,11 @@ const getDictionaryRoutes = () => ({
39
39
  url: `${baseURL}/keys`,
40
40
  method: "GET"
41
41
  },
42
+ getDictionariesUpdateTimestamp: {
43
+ urlModel: "/update",
44
+ url: `${baseURL}/update`,
45
+ method: "GET"
46
+ },
42
47
  getDictionary: {
43
48
  urlModel: "/:dictionaryKey",
44
49
  url: ({ dictionaryKey }) => `${baseURL}/${dictionaryKey}`,
@@ -73,6 +78,10 @@ dictionaryRouter.get(
73
78
  getDictionaryRoutes().getDictionariesKeys.urlModel,
74
79
  import_dictionary.getDictionariesKeys
75
80
  );
81
+ dictionaryRouter.get(
82
+ getDictionaryRoutes().getDictionariesUpdateTimestamp.urlModel,
83
+ import_dictionary.getDictionariesUpdateTimestamp
84
+ );
76
85
  dictionaryRouter.get(
77
86
  getDictionaryRoutes().getDictionary.urlModel,
78
87
  import_dictionary.getDictionaryByKey
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/routes/dictionary.routes.ts"],"sourcesContent":["import type { Routes } from '@/types/Routes';\nimport {\n addDictionary,\n deleteDictionary,\n getDictionaries,\n getDictionariesKeys,\n getDictionaryByKey,\n pushDictionaries,\n updateDictionary,\n} from '@controllers/dictionary.controller';\nimport { Router } from 'express';\n\nexport const dictionaryRouter: Router = Router();\n\nexport const dictionaryRoute = '/api/dictionary';\n\nconst baseURL = () => `${process.env.BACKEND_URL}${dictionaryRoute}`;\n\nexport const getDictionaryRoutes = () =>\n ({\n getDictionaries: {\n urlModel: '/',\n url: baseURL,\n method: 'GET',\n },\n getDictionariesKeys: {\n urlModel: '/keys',\n url: `${baseURL}/keys`,\n method: 'GET',\n },\n getDictionary: {\n urlModel: '/:dictionaryKey',\n url: ({ dictionaryKey }: { dictionaryKey: string }) =>\n `${baseURL}/${dictionaryKey}`,\n method: 'GET',\n },\n addDictionary: {\n urlModel: '/',\n url: baseURL,\n method: 'POST',\n },\n pushDictionaries: {\n urlModel: '/',\n url: baseURL,\n method: 'PATCH',\n },\n updateDictionary: {\n urlModel: '/:dictionaryId',\n url: ({ dictionaryId }: { dictionaryId: string }) =>\n `${baseURL}/${dictionaryId}`,\n method: 'PUT',\n },\n deleteDictionary: {\n urlModel: '/:dictionaryId',\n url: ({ dictionaryId }: { dictionaryId: string }) =>\n `${baseURL}/${dictionaryId}`,\n method: 'DELETE',\n },\n }) satisfies Routes;\n\ndictionaryRouter.get(\n getDictionaryRoutes().getDictionaries.urlModel,\n getDictionaries\n);\n\ndictionaryRouter.get(\n getDictionaryRoutes().getDictionariesKeys.urlModel,\n getDictionariesKeys\n);\n\ndictionaryRouter.get(\n getDictionaryRoutes().getDictionary.urlModel,\n getDictionaryByKey\n);\n\ndictionaryRouter.post(\n getDictionaryRoutes().addDictionary.urlModel,\n addDictionary\n);\ndictionaryRouter.patch(\n getDictionaryRoutes().pushDictionaries.urlModel,\n pushDictionaries\n);\ndictionaryRouter.put(\n getDictionaryRoutes().updateDictionary.urlModel,\n updateDictionary\n);\ndictionaryRouter.delete(\n getDictionaryRoutes().deleteDictionary.urlModel,\n deleteDictionary\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wBAQO;AACP,qBAAuB;AAEhB,MAAM,uBAA2B,uBAAO;AAExC,MAAM,kBAAkB;AAE/B,MAAM,UAAU,MAAM,GAAG,QAAQ,IAAI,WAAW,GAAG,eAAe;AAE3D,MAAM,sBAAsB,OAChC;AAAA,EACC,iBAAiB;AAAA,IACf,UAAU;AAAA,IACV,KAAK;AAAA,IACL,QAAQ;AAAA,EACV;AAAA,EACA,qBAAqB;AAAA,IACnB,UAAU;AAAA,IACV,KAAK,GAAG,OAAO;AAAA,IACf,QAAQ;AAAA,EACV;AAAA,EACA,eAAe;AAAA,IACb,UAAU;AAAA,IACV,KAAK,CAAC,EAAE,cAAc,MACpB,GAAG,OAAO,IAAI,aAAa;AAAA,IAC7B,QAAQ;AAAA,EACV;AAAA,EACA,eAAe;AAAA,IACb,UAAU;AAAA,IACV,KAAK;AAAA,IACL,QAAQ;AAAA,EACV;AAAA,EACA,kBAAkB;AAAA,IAChB,UAAU;AAAA,IACV,KAAK;AAAA,IACL,QAAQ;AAAA,EACV;AAAA,EACA,kBAAkB;AAAA,IAChB,UAAU;AAAA,IACV,KAAK,CAAC,EAAE,aAAa,MACnB,GAAG,OAAO,IAAI,YAAY;AAAA,IAC5B,QAAQ;AAAA,EACV;AAAA,EACA,kBAAkB;AAAA,IAChB,UAAU;AAAA,IACV,KAAK,CAAC,EAAE,aAAa,MACnB,GAAG,OAAO,IAAI,YAAY;AAAA,IAC5B,QAAQ;AAAA,EACV;AACF;AAEF,iBAAiB;AAAA,EACf,oBAAoB,EAAE,gBAAgB;AAAA,EACtC;AACF;AAEA,iBAAiB;AAAA,EACf,oBAAoB,EAAE,oBAAoB;AAAA,EAC1C;AACF;AAEA,iBAAiB;AAAA,EACf,oBAAoB,EAAE,cAAc;AAAA,EACpC;AACF;AAEA,iBAAiB;AAAA,EACf,oBAAoB,EAAE,cAAc;AAAA,EACpC;AACF;AACA,iBAAiB;AAAA,EACf,oBAAoB,EAAE,iBAAiB;AAAA,EACvC;AACF;AACA,iBAAiB;AAAA,EACf,oBAAoB,EAAE,iBAAiB;AAAA,EACvC;AACF;AACA,iBAAiB;AAAA,EACf,oBAAoB,EAAE,iBAAiB;AAAA,EACvC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/routes/dictionary.routes.ts"],"sourcesContent":["import type { Routes } from '@/types/Routes';\nimport {\n addDictionary,\n deleteDictionary,\n getDictionaries,\n getDictionariesKeys,\n getDictionariesUpdateTimestamp,\n getDictionaryByKey,\n pushDictionaries,\n updateDictionary,\n} from '@controllers/dictionary.controller';\nimport { Router } from 'express';\n\nexport const dictionaryRouter: Router = Router();\n\nexport const dictionaryRoute = '/api/dictionary';\n\nconst baseURL = () => `${process.env.BACKEND_URL}${dictionaryRoute}`;\n\nexport const getDictionaryRoutes = () =>\n ({\n getDictionaries: {\n urlModel: '/',\n url: baseURL,\n method: 'GET',\n },\n getDictionariesKeys: {\n urlModel: '/keys',\n url: `${baseURL}/keys`,\n method: 'GET',\n },\n getDictionariesUpdateTimestamp: {\n urlModel: '/update',\n url: `${baseURL}/update`,\n method: 'GET',\n },\n getDictionary: {\n urlModel: '/:dictionaryKey',\n url: ({ dictionaryKey }: { dictionaryKey: string }) =>\n `${baseURL}/${dictionaryKey}`,\n method: 'GET',\n },\n addDictionary: {\n urlModel: '/',\n url: baseURL,\n method: 'POST',\n },\n pushDictionaries: {\n urlModel: '/',\n url: baseURL,\n method: 'PATCH',\n },\n updateDictionary: {\n urlModel: '/:dictionaryId',\n url: ({ dictionaryId }: { dictionaryId: string }) =>\n `${baseURL}/${dictionaryId}`,\n method: 'PUT',\n },\n deleteDictionary: {\n urlModel: '/:dictionaryId',\n url: ({ dictionaryId }: { dictionaryId: string }) =>\n `${baseURL}/${dictionaryId}`,\n method: 'DELETE',\n },\n }) satisfies Routes;\n\ndictionaryRouter.get(\n getDictionaryRoutes().getDictionaries.urlModel,\n getDictionaries\n);\n\ndictionaryRouter.get(\n getDictionaryRoutes().getDictionariesKeys.urlModel,\n getDictionariesKeys\n);\n\ndictionaryRouter.get(\n getDictionaryRoutes().getDictionariesUpdateTimestamp.urlModel,\n getDictionariesUpdateTimestamp\n);\n\ndictionaryRouter.get(\n getDictionaryRoutes().getDictionary.urlModel,\n getDictionaryByKey\n);\n\ndictionaryRouter.post(\n getDictionaryRoutes().addDictionary.urlModel,\n addDictionary\n);\ndictionaryRouter.patch(\n getDictionaryRoutes().pushDictionaries.urlModel,\n pushDictionaries\n);\ndictionaryRouter.put(\n getDictionaryRoutes().updateDictionary.urlModel,\n updateDictionary\n);\ndictionaryRouter.delete(\n getDictionaryRoutes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;AACF;AAEA,iBAAiB;AAAA,EACf,oBAAoB,EAAE,+BAA+B;AAAA,EACrD;AACF;AAEA,iBAAiB;AAAA,EACf,oBAAoB,EAAE,cAAc;AAAA,EACpC;AACF;AAEA,iBAAiB;AAAA,EACf,oBAAoB,EAAE,cAAc;AAAA,EACpC;AACF;AACA,iBAAiB;AAAA,EACf,oBAAoB,EAAE,iBAAiB;AAAA,EACvC;AACF;AACA,iBAAiB;AAAA,EACf,oBAAoB,EAAE,iBAAiB;AAAA,EACvC;AACF;AACA,iBAAiB;AAAA,EACf,oBAAoB,EAAE,iBAAiB;AAAA,EACvC;AACF;","names":[]}
@@ -30,8 +30,8 @@ const eventListenerRoute = "/api/event-listener";
30
30
  const baseURL = () => `${process.env.BACKEND_URL}${eventListenerRoute}`;
31
31
  const eventListenerRoutes = () => ({
32
32
  checkDictionaryChangeSSE: {
33
- urlModel: "/:accessToken",
34
- url: ({ accessToken }) => `${baseURL()}/${accessToken}`,
33
+ urlModel: "/",
34
+ url: baseURL(),
35
35
  method: "GET"
36
36
  }
37
37
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/routes/eventListener.routes.ts"],"sourcesContent":["import type { Routes } from '@/types/Routes';\nimport { listenChangeSSE } from '@controllers/eventListener.controller';\nimport { Router } from 'express';\n\nexport const eventListenerRouter: Router = Router();\n\nexport const eventListenerRoute = '/api/event-listener';\n\nconst baseURL = () => `${process.env.BACKEND_URL}${eventListenerRoute}`;\n\nexport const eventListenerRoutes = () =>\n ({\n checkDictionaryChangeSSE: {\n urlModel: '/:accessToken',\n url: ({ accessToken }: { accessToken: string }) =>\n `${baseURL()}/${accessToken}`,\n method: 'GET',\n },\n }) satisfies Routes;\n\neventListenerRouter.get(\n eventListenerRoutes().checkDictionaryChangeSSE.urlModel,\n listenChangeSSE\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAAgC;AAChC,qBAAuB;AAEhB,MAAM,0BAA8B,uBAAO;AAE3C,MAAM,qBAAqB;AAElC,MAAM,UAAU,MAAM,GAAG,QAAQ,IAAI,WAAW,GAAG,kBAAkB;AAE9D,MAAM,sBAAsB,OAChC;AAAA,EACC,0BAA0B;AAAA,IACxB,UAAU;AAAA,IACV,KAAK,CAAC,EAAE,YAAY,MAClB,GAAG,QAAQ,CAAC,IAAI,WAAW;AAAA,IAC7B,QAAQ;AAAA,EACV;AACF;AAEF,oBAAoB;AAAA,EAClB,oBAAoB,EAAE,yBAAyB;AAAA,EAC/C;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/routes/eventListener.routes.ts"],"sourcesContent":["import type { Routes } from '@/types/Routes';\nimport { listenChangeSSE } from '@controllers/eventListener.controller';\nimport { Router } from 'express';\n\nexport const eventListenerRouter: Router = Router();\n\nexport const eventListenerRoute = '/api/event-listener';\n\nconst baseURL = () => `${process.env.BACKEND_URL}${eventListenerRoute}`;\n\nexport const eventListenerRoutes = () =>\n ({\n checkDictionaryChangeSSE: {\n urlModel: '/',\n url: baseURL(),\n method: 'GET',\n },\n }) satisfies Routes;\n\neventListenerRouter.get(\n eventListenerRoutes().checkDictionaryChangeSSE.urlModel,\n listenChangeSSE\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAAgC;AAChC,qBAAuB;AAEhB,MAAM,0BAA8B,uBAAO;AAE3C,MAAM,qBAAqB;AAElC,MAAM,UAAU,MAAM,GAAG,QAAQ,IAAI,WAAW,GAAG,kBAAkB;AAE9D,MAAM,sBAAsB,OAChC;AAAA,EACC,0BAA0B;AAAA,IACxB,UAAU;AAAA,IACV,KAAK,QAAQ;AAAA,IACb,QAAQ;AAAA,EACV;AACF;AAEF,oBAAoB;AAAA,EAClB,oBAAoB,EAAE,yBAAyB;AAAA,EAC/C;AACF;","names":[]}
@@ -72,11 +72,6 @@ const dictionarySchema = new import_mongoose.Schema(
72
72
  type: import_mongoose.Schema.Types.ObjectId,
73
73
  ref: "User",
74
74
  required: true
75
- },
76
- filePath: {
77
- type: Map,
78
- of: String,
79
- default: null
80
75
  }
81
76
  },
82
77
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/schemas/dictionary.schema.ts"],"sourcesContent":["import type {\n DictionarySchema,\n VersionedContentEl,\n} from '@/types/dictionary.types';\nimport { Schema } from 'mongoose';\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 filePath: {\n type: Map,\n of: String,\n default: null,\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 ret.id = ret._id.toString(); // convert _id to id\n delete ret._id; // remove _id\n },\n },\n toObject: {\n virtuals: true,\n transform(doc, ret: any) {\n ret.id = ret._id; // convert _id to id\n delete ret._id; // remove _id\n },\n },\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAAuB;AAEvB,MAAM,2BAA2B,IAAI;AAAA,EACnC;AAAA,IACE,MAAM;AAAA,MACJ,MAAM;AAAA,IACR;AAAA,IACA,aAAa;AAAA,MACX,MAAM;AAAA,IACR;AAAA,IACA,SAAS;AAAA,MACP,MAAM,uBAAO,MAAM;AAAA,MACnB,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,EACd;AACF;AAEO,MAAM,mBAAmB,IAAI;AAAA,EAClC;AAAA,IACE,YAAY;AAAA,MACV,MAAM,CAAC,uBAAO,MAAM,QAAQ;AAAA,MAC5B,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,IACA,KAAK;AAAA,MACH,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IACA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,IACA,aAAa;AAAA,MACX,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,IACA,MAAM;AAAA,MACJ,MAAM,CAAC,MAAM;AAAA,MACb,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,UAAU;AAAA,MACV,SAAS;AAAA,IACX;AAAA,IACA,WAAW;AAAA,MACT,MAAM,uBAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,IACA,UAAU;AAAA,MACR,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,SAAS;AAAA,IACX;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,IAEZ,QAAQ;AAAA,MACN,UAAU;AAAA;AAAA,MACV,YAAY;AAAA;AAAA,MACZ,UAAU,KAAK,KAAU;AACvB,YAAI,KAAK,IAAI,IAAI,SAAS;AAC1B,eAAO,IAAI;AAAA,MACb;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,UAAU;AAAA,MACV,UAAU,KAAK,KAAU;AACvB,YAAI,KAAK,IAAI;AACb,eAAO,IAAI;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/schemas/dictionary.schema.ts"],"sourcesContent":["import type {\n DictionarySchema,\n VersionedContentEl,\n} from '@/types/dictionary.types';\nimport { Schema } from 'mongoose';\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 ret.id = ret._id.toString(); // convert _id to id\n delete ret._id; // remove _id\n },\n },\n toObject: {\n virtuals: true,\n transform(doc, ret: any) {\n ret.id = ret._id; // convert _id to id\n delete ret._id; // remove _id\n },\n },\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAAuB;AAEvB,MAAM,2BAA2B,IAAI;AAAA,EACnC;AAAA,IACE,MAAM;AAAA,MACJ,MAAM;AAAA,IACR;AAAA,IACA,aAAa;AAAA,MACX,MAAM;AAAA,IACR;AAAA,IACA,SAAS;AAAA,MACP,MAAM,uBAAO,MAAM;AAAA,MACnB,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,EACd;AACF;AAEO,MAAM,mBAAmB,IAAI;AAAA,EAClC;AAAA,IACE,YAAY;AAAA,MACV,MAAM,CAAC,uBAAO,MAAM,QAAQ;AAAA,MAC5B,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,IACA,KAAK;AAAA,MACH,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IACA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,IACA,aAAa;AAAA,MACX,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,IACA,MAAM;AAAA,MACJ,MAAM,CAAC,MAAM;AAAA,MACb,SAAS,CAAC;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,UAAU;AAAA,MACV,SAAS;AAAA,IACX;AAAA,IACA,WAAW;AAAA,MACT,MAAM,uBAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,IAEZ,QAAQ;AAAA,MACN,UAAU;AAAA;AAAA,MACV,YAAY;AAAA;AAAA,MACZ,UAAU,KAAK,KAAU;AACvB,YAAI,KAAK,IAAI,IAAI,SAAS;AAC1B,eAAO,IAAI;AAAA,MACb;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,UAAU;AAAA,MACV,UAAU,KAAK,KAAU;AACvB,YAAI,KAAK,IAAI;AACb,eAAO,IAAI;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -62,10 +62,10 @@ const getDictionaryById = async (dictionaryId) => {
62
62
  const dictionaries = await import_dictionary.DictionaryModel.aggregate([
63
63
  // Stage 1: Match the document by ID
64
64
  { $match: { _id: id } },
65
- // Stage 2: Add the 'availableVersions' field
65
+ // Stage 2: Add the 'versions' field
66
66
  {
67
67
  $addFields: {
68
- availableVersions: {
68
+ versions: {
69
69
  $map: {
70
70
  input: { $objectToArray: "$content" },
71
71
  as: "version",
@@ -88,10 +88,10 @@ const getDictionariesByKeys = async (dictionaryKeys, projectId) => {
88
88
  const dictionaries = await import_dictionary.DictionaryModel.aggregate([
89
89
  // Stage 1: Match the document by key
90
90
  { $match: { key: { $in: dictionaryKeys }, projectIds: projectId } },
91
- // Stage 2: Add the 'availableVersions' field
91
+ // Stage 2: Add the 'versions' field
92
92
  {
93
93
  $addFields: {
94
- availableVersions: {
94
+ versions: {
95
95
  $map: {
96
96
  input: { $objectToArray: "$content" },
97
97
  as: "version",
@@ -121,10 +121,10 @@ const getDictionariesByTags = async (tags, projectId) => {
121
121
  projectIds: projectId
122
122
  }
123
123
  },
124
- // Stage 2: Add the 'availableVersions' field
124
+ // Stage 2: Add the 'versions' field
125
125
  {
126
126
  $addFields: {
127
- availableVersions: {
127
+ versions: {
128
128
  $map: {
129
129
  input: { $objectToArray: "$content" },
130
130
  as: "version",
@@ -237,11 +237,11 @@ const getVersionNumber = (version) => {
237
237
  };
238
238
  const incrementVersion = (dictionary) => {
239
239
  const VERSION_PREFIX = "v";
240
- const availableVersions = [...dictionary.content.keys() ?? []];
241
- const lastVersion = availableVersions[availableVersions.length - 1];
240
+ const versions = [...dictionary.content.keys() ?? []];
241
+ const lastVersion = versions[versions.length - 1];
242
242
  let newNumber = getVersionNumber(lastVersion) + 1;
243
243
  let newVersion = `${VERSION_PREFIX}${newNumber}`;
244
- while (availableVersions.includes(newVersion)) {
244
+ while (versions.includes(newVersion)) {
245
245
  newNumber += 1;
246
246
  newVersion = `${VERSION_PREFIX}${newNumber}`;
247
247
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/dictionary.service.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionaryData,\n DictionaryDocument,\n} from '@/types/dictionary.types';\nimport type { Project } from '@/types/project.types';\nimport { DictionaryModel } from '@models/dictionary.model';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { GenericError } from '@utils/errors';\nimport type { DictionaryFilters } from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport { removeObjectKeys } from '@utils/removeObjectKeys';\nimport {\n validateDictionary,\n type DictionaryFields,\n} from '@utils/validation/validateDictionary';\nimport { Types } from 'mongoose';\n\n/**\n * Finds dictionaries based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of dictionaries matching the filters.\n */\nexport const findDictionaries = async (\n filters: DictionaryFilters,\n skip = 0,\n limit = 100\n): Promise<DictionaryDocument[]> => {\n try {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the filters\n { $match: filters },\n\n // Stage 2: Skip for pagination\n { $skip: skip },\n\n // Stage 3: Limit the number of documents\n { $limit: limit },\n ]);\n\n const formattedResults = dictionaries.map(\n (result) => new DictionaryModel(result)\n );\n\n return formattedResults;\n } catch (error) {\n console.error('Error fetching dictionaries:', error);\n throw error;\n }\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\n/**\n * Finds a dictionary by its ID and includes the 'availableVersions' field.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID with available versions.\n */\nexport const getDictionaryById = async (\n dictionaryId: string | Types.ObjectId\n): Promise<DictionaryDocument> => {\n const id = Types.ObjectId.isValid(dictionaryId as string)\n ? new Types.ObjectId(dictionaryId as string)\n : dictionaryId;\n\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by ID\n { $match: { _id: id } },\n\n // Stage 2: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n if (!dictionaries.length) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return new DictionaryModel(dictionaries[0]);\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryKey - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\nexport const getDictionaryByKey = async (\n dictionaryKey: string,\n projectId: string | Types.ObjectId\n): Promise<DictionaryDocument> => {\n const dictionaries = await getDictionariesByKeys([dictionaryKey], projectId);\n\n return dictionaries[0];\n};\n\nexport const getDictionariesByKeys = async (\n dictionaryKeys: string[],\n projectId: string | Types.ObjectId\n): Promise<DictionaryDocument[]> => {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by key\n { $match: { key: { $in: dictionaryKeys }, projectIds: projectId } },\n\n // Stage 2: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n if (!dictionaries) {\n throw new GenericError('DICTIONARY_NOT_FOUND', {\n dictionaryKeys,\n projectId,\n });\n }\n\n const formattedResults = dictionaries.map(\n (result) => new DictionaryModel(result)\n );\n\n return formattedResults;\n};\n\nexport const getDictionariesByTags = async (\n tags: string[],\n projectId: string | Project['id']\n): Promise<DictionaryDocument[]> => {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by tags\n {\n $match: {\n tags: { $in: tags },\n projectIds: projectId,\n },\n },\n\n // Stage 2: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n const formattedResults = dictionaries.map(\n (result) => new DictionaryModel(result)\n );\n\n return formattedResults;\n};\n\n/**\n * Counts the total number of dictionaries that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of dictionaries.\n */\nexport const countDictionaries = async (\n filters: DictionaryFilters\n): Promise<number> => {\n const result = await DictionaryModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('DICTIONARY_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new dictionary in the database.\n * @param dictionary - The dictionary data to create.\n * @returns The created dictionary.\n */\nexport const createDictionary = async (\n dictionary: DictionaryData\n): Promise<DictionaryDocument> => {\n const errors = await validateDictionary(dictionary);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n errors,\n });\n }\n\n return await DictionaryModel.create(dictionary);\n};\n\ntype GetExistingDictionaryResult = {\n existingDictionariesKey: string[];\n newDictionariesKey: string[];\n};\n\n/**\n * Gets the existing dictionaries from the provided list of keys.\n * @param dictionariesKeys - List of dictionary keys to check.\n * @param projectId - The ID of the project to check the dictionaries against.\n * @returns The existing dictionaries and the new dictionaries.\n */\nexport const getExistingDictionaryKey = async (\n dictionariesKeys: string[],\n projectId: string | Types.ObjectId\n): Promise<GetExistingDictionaryResult> => {\n // Fetch dictionaries from the database where the key is in the provided list\n const existingDictionaries = await DictionaryModel.find({\n key: { $in: dictionariesKeys },\n projectIds: projectId,\n });\n\n // Map existing dictionaries to a LocalDictionary object\n const existingDictionariesKey: string[] = [];\n const newDictionariesKey: string[] = [];\n\n for (const key of dictionariesKeys) {\n const isDictionaryExist = existingDictionaries.some(\n (dictionary) => dictionary.key === key\n );\n\n if (isDictionaryExist) {\n existingDictionariesKey.push(key);\n } else {\n newDictionariesKey.push(key);\n }\n }\n\n return { existingDictionariesKey, newDictionariesKey };\n};\n\n/**\n * Updates an existing dictionary in the database by its ID.\n * @param dictionaryId - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryById = async (\n dictionaryId: string | Types.ObjectId,\n dictionary: Partial<Dictionary>\n): Promise<DictionaryDocument> => {\n const dictionaryObject = ensureMongoDocumentToObject(dictionary);\n const dictionaryToUpdate = removeObjectKeys(dictionaryObject, [\n 'id',\n ]) as unknown as Partial<Dictionary>;\n\n const updatedKeys = Object.keys(dictionaryToUpdate) as DictionaryFields;\n const errors = await validateDictionary(dictionaryToUpdate, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryId,\n errors,\n });\n }\n\n const result = await DictionaryModel.updateOne(\n { _id: dictionaryId },\n dictionaryToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryId });\n }\n\n const updatedDictionary = await getDictionaryById(dictionaryId);\n\n return updatedDictionary;\n};\n\n/**\n * Updates an existing dictionary in the database by its key.\n * @param dictionaryKey - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryByKey = async (\n dictionaryKey: string,\n dictionary: Partial<Dictionary>,\n projectId: string | Types.ObjectId\n): Promise<DictionaryDocument> => {\n const dictionaryObject = ensureMongoDocumentToObject(dictionary);\n const dictionaryToUpdate = removeObjectKeys(dictionaryObject, [\n 'id',\n ]) as unknown as Partial<Dictionary>;\n\n const updatedKeys = Object.keys(dictionaryToUpdate) as DictionaryFields;\n const errors = await validateDictionary(dictionaryToUpdate, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryKey,\n projectId,\n errors,\n });\n }\n\n const result = await DictionaryModel.updateOne(\n { key: dictionaryKey, projectIds: projectId },\n dictionaryToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryKey });\n }\n\n const updatedDictionary = await getDictionaryByKey(dictionaryKey, projectId);\n\n return updatedDictionary;\n};\n\n/**\n * Deletes a dictionary from the database by its ID.\n * @param dictionaryId - The ID of the dictionary to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteDictionaryById = async (\n dictionaryId: string\n): Promise<DictionaryDocument> => {\n const dictionary = await DictionaryModel.findByIdAndDelete(dictionaryId);\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary;\n};\n\n// Function to extract the numeric part of the version\nconst getVersionNumber = (version: string): number => {\n const match = version.match(/^v(\\d+)$/);\n if (!match) {\n throw new Error(`Invalid version format: ${version}`);\n }\n return parseInt(match[1], 10);\n};\n\nexport const incrementVersion = (dictionary: Dictionary): string => {\n const VERSION_PREFIX = 'v';\n\n const availableVersions = [...(dictionary.content.keys() ?? [])];\n const lastVersion = availableVersions[availableVersions.length - 1];\n\n // Start with the next version number\n let newNumber = getVersionNumber(lastVersion) + 1;\n let newVersion = `${VERSION_PREFIX}${newNumber}`;\n\n // Loop until a unique version is found\n while (availableVersions.includes(newVersion)) {\n newNumber += 1;\n newVersion = `${VERSION_PREFIX}${newNumber}`;\n }\n\n return newVersion;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,wBAAgC;AAChC,yCAA4C;AAC5C,oBAA6B;AAE7B,8BAAiC;AACjC,gCAGO;AACP,sBAAsB;AASf,MAAM,mBAAmB,OAC9B,SACA,OAAO,GACP,QAAQ,QAC0B;AAClC,MAAI;AACF,UAAM,eAAe,MAAM,kCAAgB,UAA8B;AAAA;AAAA,MAEvE,EAAE,QAAQ,QAAQ;AAAA;AAAA,MAGlB,EAAE,OAAO,KAAK;AAAA;AAAA,MAGd,EAAE,QAAQ,MAAM;AAAA,IAClB,CAAC;AAED,UAAM,mBAAmB,aAAa;AAAA,MACpC,CAAC,WAAW,IAAI,kCAAgB,MAAM;AAAA,IACxC;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,gCAAgC,KAAK;AACnD,UAAM;AAAA,EACR;AACF;AAYO,MAAM,oBAAoB,OAC/B,iBACgC;AAChC,QAAM,KAAK,sBAAM,SAAS,QAAQ,YAAsB,IACpD,IAAI,sBAAM,SAAS,YAAsB,IACzC;AAEJ,QAAM,eAAe,MAAM,kCAAgB,UAA8B;AAAA;AAAA,IAEvE,EAAE,QAAQ,EAAE,KAAK,GAAG,EAAE;AAAA;AAAA,IAGtB;AAAA,MACE,YAAY;AAAA,QACV,mBAAmB;AAAA,UACjB,MAAM;AAAA,YACJ,OAAO,EAAE,gBAAgB,WAAW;AAAA,YACpC,IAAI;AAAA,YACJ,IAAI;AAAA,UACN;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,E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mB,CAAC,YAA4B;AACpD,QAAM,QAAQ,QAAQ,MAAM,UAAU;AACtC,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,2BAA2B,OAAO,EAAE;AAAA,EACtD;AACA,SAAO,SAAS,MAAM,CAAC,GAAG,EAAE;AAC9B;AAEO,MAAM,mBAAmB,CAAC,eAAmC;AAClE,QAAM,iBAAiB;AAEvB,QAAM,oBAAoB,CAAC,GAAI,WAAW,QAAQ,KAAK,KAAK,CAAC,CAAE;AAC/D,QAAM,cAAc,kBAAkB,kBAAkB,SAAS,CAAC;AAGlE,MAAI,YAAY,iBAAiB,WAAW,IAAI;AAChD,MAAI,aAAa,GAAG,cAAc,GAAG,SAAS;AAG9C,SAAO,kBAAkB,SAAS,UAAU,GAAG;AAC7C,iBAAa;AACb,iBAAa,GAAG,cAAc,GAAG,SAAS;AAAA,EAC5C;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/services/dictionary.service.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionaryData,\n DictionaryDocument,\n} from '@/types/dictionary.types';\nimport type { Project } from '@/types/project.types';\nimport { DictionaryModel } from '@models/dictionary.model';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { GenericError } from '@utils/errors';\nimport type { DictionaryFilters } from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport { removeObjectKeys } from '@utils/removeObjectKeys';\nimport {\n validateDictionary,\n type DictionaryFields,\n} from '@utils/validation/validateDictionary';\nimport { Types } from 'mongoose';\n\n/**\n * Finds dictionaries based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of dictionaries matching the filters.\n */\nexport const findDictionaries = async (\n filters: DictionaryFilters,\n skip = 0,\n limit = 100\n): Promise<DictionaryDocument[]> => {\n try {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the filters\n { $match: filters },\n\n // Stage 2: Skip for pagination\n { $skip: skip },\n\n // Stage 3: Limit the number of documents\n { $limit: limit },\n ]);\n\n const formattedResults = dictionaries.map(\n (result) => new DictionaryModel(result)\n );\n\n return formattedResults;\n } catch (error) {\n console.error('Error fetching dictionaries:', error);\n throw error;\n }\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\n/**\n * Finds a dictionary by its ID and includes the 'versions' field.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID with available versions.\n */\nexport const getDictionaryById = async (\n dictionaryId: string | Types.ObjectId\n): Promise<DictionaryDocument> => {\n const id = Types.ObjectId.isValid(dictionaryId as string)\n ? new Types.ObjectId(dictionaryId as string)\n : dictionaryId;\n\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by ID\n { $match: { _id: id } },\n\n // Stage 2: Add the 'versions' field\n {\n $addFields: {\n versions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n if (!dictionaries.length) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return new DictionaryModel(dictionaries[0]);\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryKey - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\nexport const getDictionaryByKey = async (\n dictionaryKey: string,\n projectId: string | Types.ObjectId\n): Promise<DictionaryDocument> => {\n const dictionaries = await getDictionariesByKeys([dictionaryKey], projectId);\n\n return dictionaries[0];\n};\n\nexport const getDictionariesByKeys = async (\n dictionaryKeys: string[],\n projectId: string | Types.ObjectId\n): Promise<DictionaryDocument[]> => {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by key\n { $match: { key: { $in: dictionaryKeys }, projectIds: projectId } },\n\n // Stage 2: Add the 'versions' field\n {\n $addFields: {\n versions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n if (!dictionaries) {\n throw new GenericError('DICTIONARY_NOT_FOUND', {\n dictionaryKeys,\n projectId,\n });\n }\n\n const formattedResults = dictionaries.map(\n (result) => new DictionaryModel(result)\n );\n\n return formattedResults;\n};\n\nexport const getDictionariesByTags = async (\n tags: string[],\n projectId: string | Project['id']\n): Promise<DictionaryDocument[]> => {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by tags\n {\n $match: {\n tags: { $in: tags },\n projectIds: projectId,\n },\n },\n\n // Stage 2: Add the 'versions' field\n {\n $addFields: {\n versions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n const formattedResults = dictionaries.map(\n (result) => new DictionaryModel(result)\n );\n\n return formattedResults;\n};\n\n/**\n * Counts the total number of dictionaries that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of dictionaries.\n */\nexport const countDictionaries = async (\n filters: DictionaryFilters\n): Promise<number> => {\n const result = await DictionaryModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('DICTIONARY_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new dictionary in the database.\n * @param dictionary - The dictionary data to create.\n * @returns The created dictionary.\n */\nexport const createDictionary = async (\n dictionary: DictionaryData\n): Promise<DictionaryDocument> => {\n const errors = await validateDictionary(dictionary);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n errors,\n });\n }\n\n return await DictionaryModel.create(dictionary);\n};\n\ntype GetExistingDictionaryResult = {\n existingDictionariesKey: string[];\n newDictionariesKey: string[];\n};\n\n/**\n * Gets the existing dictionaries from the provided list of keys.\n * @param dictionariesKeys - List of dictionary keys to check.\n * @param projectId - The ID of the project to check the dictionaries against.\n * @returns The existing dictionaries and the new dictionaries.\n */\nexport const getExistingDictionaryKey = async (\n dictionariesKeys: string[],\n projectId: string | Types.ObjectId\n): Promise<GetExistingDictionaryResult> => {\n // Fetch dictionaries from the database where the key is in the provided list\n const existingDictionaries = await DictionaryModel.find({\n key: { $in: dictionariesKeys },\n projectIds: projectId,\n });\n\n // Map existing dictionaries to a LocalDictionary object\n const existingDictionariesKey: string[] = [];\n const newDictionariesKey: string[] = [];\n\n for (const key of dictionariesKeys) {\n const isDictionaryExist = existingDictionaries.some(\n (dictionary) => dictionary.key === key\n );\n\n if (isDictionaryExist) {\n existingDictionariesKey.push(key);\n } else {\n newDictionariesKey.push(key);\n }\n }\n\n return { existingDictionariesKey, newDictionariesKey };\n};\n\n/**\n * Updates an existing dictionary in the database by its ID.\n * @param dictionaryId - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryById = async (\n dictionaryId: string | Types.ObjectId,\n dictionary: Partial<Dictionary>\n): Promise<DictionaryDocument> => {\n const dictionaryObject = ensureMongoDocumentToObject(dictionary);\n const dictionaryToUpdate = removeObjectKeys(dictionaryObject, [\n 'id',\n ]) as unknown as Partial<Dictionary>;\n\n const updatedKeys = Object.keys(dictionaryToUpdate) as DictionaryFields;\n const errors = await validateDictionary(dictionaryToUpdate, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryId,\n errors,\n });\n }\n\n const result = await DictionaryModel.updateOne(\n { _id: dictionaryId },\n dictionaryToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryId });\n }\n\n const updatedDictionary = await getDictionaryById(dictionaryId);\n\n return updatedDictionary;\n};\n\n/**\n * Updates an existing dictionary in the database by its key.\n * @param dictionaryKey - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryByKey = async (\n dictionaryKey: string,\n dictionary: Partial<Dictionary>,\n projectId: string | Types.ObjectId\n): Promise<DictionaryDocument> => {\n const dictionaryObject = ensureMongoDocumentToObject(dictionary);\n const dictionaryToUpdate = removeObjectKeys(dictionaryObject, [\n 'id',\n ]) as unknown as Partial<Dictionary>;\n\n const updatedKeys = Object.keys(dictionaryToUpdate) as DictionaryFields;\n const errors = await validateDictionary(dictionaryToUpdate, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryKey,\n projectId,\n errors,\n });\n }\n\n const result = await DictionaryModel.updateOne(\n { key: dictionaryKey, projectIds: projectId },\n dictionaryToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryKey });\n }\n\n const updatedDictionary = await getDictionaryByKey(dictionaryKey, projectId);\n\n return updatedDictionary;\n};\n\n/**\n * Deletes a dictionary from the database by its ID.\n * @param dictionaryId - The ID of the dictionary to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteDictionaryById = async (\n dictionaryId: string\n): Promise<DictionaryDocument> => {\n const dictionary = await DictionaryModel.findByIdAndDelete(dictionaryId);\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary;\n};\n\n// Function to extract the numeric part of the version\nconst getVersionNumber = (version: string): number => {\n const match = version.match(/^v(\\d+)$/);\n if (!match) {\n throw new Error(`Invalid version format: ${version}`);\n }\n return parseInt(match[1], 10);\n};\n\nexport const incrementVersion = (dictionary: Dictionary): string => {\n const VERSION_PREFIX = 'v';\n\n const versions = [...(dictionary.content.keys() ?? [])];\n const lastVersion = versions[versions.length - 1];\n\n // Start with the next version number\n let newNumber = getVersionNumber(lastVersion) + 1;\n let newVersion = `${VERSION_PREFIX}${newNumber}`;\n\n // Loop until a unique version is found\n while (versions.includes(newVersion)) {\n newNumber += 1;\n newVersion = `${VERSION_PREFIX}${newNumber}`;\n }\n\n return newVersion;\n};\n"],"mappings":";;;;;;;;;;;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E,QAAM,iBAAiB;AAEvB,QAAM,WAAW,CAAC,GAAI,WAAW,QAAQ,KAAK,KAAK,CAAC,CAAE;AACtD,QAAM,cAAc,SAAS,SAAS,SAAS,CAAC;AAGhD,MAAI,YAAY,iBAAiB,WAAW,IAAI;AAChD,MAAI,aAAa,GAAG,cAAc,GAAG,SAAS;AAG9C,SAAO,SAAS,SAAS,UAAU,GAAG;AACpC,iBAAa;AACb,iBAAa,GAAG,cAAc,GAAG,SAAS;AAAA,EAC5C;AAEA,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/project.service.ts"],"sourcesContent":["import type {\n Project,\n ProjectData,\n ProjectDocument,\n} from '@/types/project.types';\nimport { ProjectModel } from '@models/project.model';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { GenericError } from '@utils/errors';\nimport type { ProjectFilters } from '@utils/filtersAndPagination/getProjectFiltersAndPagination';\nimport { removeObjectKeys } from '@utils/removeObjectKeys';\nimport {\n type ProjectFields,\n validateProject,\n} from '@utils/validation/validateProject';\nimport type { Types } from 'mongoose';\n\n/**\n * Finds projects based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of projects matching the filters.\n */\nexport const findProjects = async (\n filters: ProjectFilters,\n skip = 0,\n limit = 100\n): Promise<ProjectDocument[]> =>\n await ProjectModel.find(filters).skip(skip).limit(limit);\n\n/**\n * Finds a project by its ID.\n * @param projectId - The ID of the project to find.\n * @returns The project matching the ID.\n */\nexport const getProjectById = async (\n projectId: string | Types.ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findById(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n\n/**\n * Counts the total number of projects that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of projects.\n */\nexport const countProjects = async (\n filters: ProjectFilters\n): Promise<number> => {\n const result = await ProjectModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('PROJECT_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new project in the database.\n * @param project - The project data to create.\n * @returns The created project.\n */\nexport const createProject = async (\n project: ProjectData\n): Promise<ProjectDocument> => {\n if ((project as Partial<Project>).oAuth2Access) {\n delete (project as Partial<Project>).oAuth2Access;\n }\n\n const errors = await validateProject(project, ['name']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', { errors });\n }\n\n return await ProjectModel.create(project);\n};\n\n/**\n * Updates an existing project in the database by its ID.\n * @param projectId - The ID of the project to update.\n * @param project - The updated project data.\n * @returns The updated project.\n */\nexport const updateProjectById = async (\n projectId: string | Types.ObjectId,\n project: Partial<Project>\n): Promise<ProjectDocument> => {\n const projectObject = ensureMongoDocumentToObject(project);\n const projectToUpdate = removeObjectKeys(projectObject, [\n 'id',\n 'oAuth2Access',\n 'organizationId',\n ]);\n\n const updatedKeys = Object.keys(projectToUpdate) as ProjectFields;\n\n const errors = validateProject(project, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', {\n projectId,\n errors,\n });\n }\n\n const result = await ProjectModel.updateOne(\n { _id: projectId },\n projectToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('PROJECT_UPDATE_FAILED', { projectId });\n }\n\n return await getProjectById(projectId);\n};\n\n/**\n * Deletes a project from the database by its ID.\n * @param projectId - The ID of the project to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteProjectById = async (\n projectId: string | Types.ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findByIdAndDelete(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA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AAA,EACH;AAEA,QAAM,SAAS,MAAM,4BAAa;AAAA,IAChC,EAAE,KAAK,UAAU;AAAA,IACjB;AAAA,EACF;AAEA,MAAI,OAAO,iBAAiB,GAAG;AAC7B,UAAM,IAAI,2BAAa,yBAAyB,EAAE,UAAU,CAAC;AAAA,EAC/D;AAEA,SAAO,MAAM,eAAe,SAAS;AACvC;AAOO,MAAM,oBAAoB,OAC/B,cAC6B;AAC7B,QAAM,UAAU,MAAM,4BAAa,kBAAkB,SAAS;AAE9D,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,2BAAa,uBAAuB,EAAE,UAAU,CAAC;AAAA,EAC7D;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/services/project.service.ts"],"sourcesContent":["import type {\n Project,\n ProjectAPI,\n ProjectData,\n ProjectDocument,\n} from '@/types/project.types';\nimport { ProjectModel } from '@models/project.model';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { GenericError } from '@utils/errors';\nimport type { ProjectFilters } from '@utils/filtersAndPagination/getProjectFiltersAndPagination';\nimport { removeObjectKeys } from '@utils/removeObjectKeys';\nimport {\n type ProjectFields,\n validateProject,\n} from '@utils/validation/validateProject';\nimport type { Types } from 'mongoose';\n\n/**\n * Finds projects based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of projects matching the filters.\n */\nexport const findProjects = async (\n filters: ProjectFilters,\n skip = 0,\n limit = 100\n): Promise<ProjectDocument[]> =>\n await ProjectModel.find(filters).skip(skip).limit(limit);\n\n/**\n * Finds a project by its ID.\n * @param projectId - The ID of the project to find.\n * @returns The project matching the ID.\n */\nexport const getProjectById = async (\n projectId: string | Types.ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findById(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n\n/**\n * Counts the total number of projects that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of projects.\n */\nexport const countProjects = async (\n filters: ProjectFilters\n): Promise<number> => {\n const result = await ProjectModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('PROJECT_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new project in the database.\n * @param project - The project data to create.\n * @returns The created project.\n */\nexport const createProject = async (\n project: ProjectData\n): Promise<ProjectDocument> => {\n if ((project as Partial<Project>).oAuth2Access) {\n delete (project as Partial<Project>).oAuth2Access;\n }\n\n const errors = await validateProject(project, ['name']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', { errors });\n }\n\n return await ProjectModel.create(project);\n};\n\n/**\n * Updates an existing project in the database by its ID.\n * @param projectId - The ID of the project to update.\n * @param project - The updated project data.\n * @returns The updated project.\n */\nexport const updateProjectById = async (\n projectId: string | Types.ObjectId,\n project: Partial<Project | ProjectAPI>\n): Promise<ProjectDocument> => {\n const projectObject = ensureMongoDocumentToObject(project);\n const projectToUpdate = removeObjectKeys(projectObject, [\n 'id',\n 'oAuth2Access',\n 'organizationId',\n ]);\n\n const updatedKeys = Object.keys(projectToUpdate) as ProjectFields;\n\n const errors = validateProject(project, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', {\n projectId,\n errors,\n });\n }\n\n const result = await ProjectModel.updateOne(\n { _id: projectId },\n projectToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('PROJECT_UPDATE_FAILED', { projectId });\n }\n\n return await getProjectById(projectId);\n};\n\n/**\n * Deletes a project from the database by its ID.\n * @param projectId - The ID of the project to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteProjectById = async (\n projectId: string | Types.ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findByIdAndDelete(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\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MAAM,EAAE,SAAS,GAAG;AAClC,UAAM,IAAI,2BAAa,0BAA0B;AAAA,MAC/C;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,SAAS,MAAM,4BAAa;AAAA,IAChC,EAAE,KAAK,UAAU;AAAA,IACjB;AAAA,EACF;AAEA,MAAI,OAAO,iBAAiB,GAAG;AAC7B,UAAM,IAAI,2BAAa,yBAAyB,EAAE,UAAU,CAAC;AAAA,EAC/D;AAEA,SAAO,MAAM,eAAe,SAAS;AACvC;AAOO,MAAM,oBAAoB,OAC/B,cAC6B;AAC7B,QAAM,UAAU,MAAM,4BAAa,kBAAkB,SAAS;AAE9D,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,2BAAa,uBAAuB,EAAE,UAAU,CAAC;AAAA,EAC7D;AAEA,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/user.service.ts"],"sourcesContent":["import type { User, UserDocument } from '@/types/user.types';\nimport { UserModel } from '@models/user.model';\nimport { GenericError } from '@utils/errors';\nimport type { UserFilters } from '@utils/filtersAndPagination/getUserFiltersAndPagination';\nimport {\n type FieldsToCheck,\n type UserFields,\n validateUser,\n} from '@utils/validation/validateUser';\nimport type { Types } from 'mongoose';\n\n/**\n * Creates a new user with password in the database and hashes the password.\n * @param user - User object with password not hashed.\n * @returns Created user object.\n */\nexport const createUser = async (\n user: Partial<User>\n): Promise<UserDocument> => {\n const fieldsToCheck: FieldsToCheck[] = ['email'];\n\n const errors = validateUser(user, fieldsToCheck);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('USER_INVALID_FIELDS', {\n userEmail: user.email,\n errors,\n });\n }\n\n const newUser: UserDocument = await UserModel.create(user);\n\n if (!newUser) {\n throw new GenericError('USER_CREATION_FAILED', { userEmail: user.email });\n }\n\n return newUser;\n};\n\n/**\n * Retrieves a user by email.\n * @param email - User's email.\n * @returns User object or null if no user was found.\n */\nexport const getUserByEmail = async (\n email: string\n): Promise<UserDocument | null> => {\n return await UserModel.findOne({ email });\n};\n\n/**\n * Retrieves users list by email.\n * @param emails - Users email.\n * @returns User object or null if no user was found.\n */\nexport const getUsersByEmails = async (\n emails: string[]\n): Promise<UserDocument[] | null> => {\n return await UserModel.find({ email: { $in: emails } });\n};\n\n/**\n * Checks if a user exists by email.\n * @param email - User's email.\n * @returns True if the user exists, false otherwise.\n */\nexport const checkUserExists = async (email: string): Promise<boolean> => {\n const user = await UserModel.exists({ email });\n return user !== null;\n};\n\n/**\n * Retrieves a user by ID.\n * @param userId - User's ID.\n * @returns User object or null if no user was found.\n */\nexport const getUserById = async (\n userId: string | Types.ObjectId\n): Promise<UserDocument | null> => await UserModel.findById(userId);\n\n/**\n * Retrieves a user by ID.\n * @param userId - User's ID.\n * @returns User object or null if no user was found.\n */\nexport const getUsersByIds = async (\n userIds: (string | Types.ObjectId)[]\n): Promise<UserDocument[] | null> =>\n await UserModel.find({ _id: { $in: userIds } });\n\n/**\n * Finds users based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of users matching the filters.\n */\nexport const findUsers = async (\n filters: UserFilters,\n skip: number,\n limit: number\n): Promise<UserDocument[]> => {\n return await UserModel.find(filters).skip(skip).limit(limit);\n};\n\n/**\n * Counts the total number of users that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of users.\n */\nexport const countUsers = async (filters: UserFilters): Promise<number> => {\n const count = await UserModel.countDocuments(filters);\n\n if (typeof count === 'undefined') {\n throw new GenericError('USER_COUNT_FAILED');\n }\n\n return count;\n};\n\n/**\n * Updates a user's information.\n * @param user - The user object.\n * @param updates - The updates to apply to the user.\n * @returns The updated user.\n */\nexport const updateUserById = async (\n userId: string | Types.ObjectId,\n updates: Partial<User>\n): Promise<UserDocument> => {\n const keyToValidate = Object.keys(updates) as UserFields;\n const errors = validateUser(updates, keyToValidate);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('USER_INVALID_FIELDS', {\n userId,\n errors,\n });\n }\n\n const result = await UserModel.updateOne({ _id: userId }, { $set: updates });\n\n if (result.matchedCount === 0) {\n throw new GenericError('USER_UPDATE_FAILED', { userId });\n }\n\n const updatedUser = await UserModel.findById(userId);\n\n if (!updatedUser) {\n throw new GenericError('USER_UPDATED_USER_NOT_FOUND', { userId });\n }\n\n return updatedUser;\n};\n\n/**\n * Deletes a user from the database.\n * @param userId - The user object.\n * @returns\n */\nexport const deleteUser = async (\n userId: string | Types.ObjectId\n): Promise<UserDocument> => {\n await getUserById(userId);\n\n const user = await UserModel.findByIdAndDelete(userId);\n\n if (!user) {\n throw new GenericError('USER_NOT_FOUND', { userId });\n }\n\n return user;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAA0B;AAC1B,oBAA6B;AAE7B,0BAIO;AAQA,MAAM,aAAa,OACxB,SAC0B;AAC1B,QAAM,gBAAiC,CAAC,OAAO;AAE/C,QAAM,aAAS,kCAAa,MAAM,aAAa;AAE/C,MAAI,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAClC,UAAM,IAAI,2BAAa,uBAAuB;AAAA,MAC5C,WAAW,KAAK;AAAA,MAChB;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,UAAwB,MAAM,sBAAU,OAAO,IAAI;AAEzD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,2BAAa,wBAAwB,EAAE,WAAW,KAAK,MAAM,CAAC;AAAA,EAC1E;AAEA,SAAO;AACT;AAOO,MAAM,iBAAiB,OAC5B,UACiC;AACjC,SAAO,MAAM,sBAAU,QAAQ,EAAE,MAAM,CAAC;AAC1C;AAOO,MAAM,mBAAmB,OAC9B,WACmC;AACnC,SAAO,MAAM,sBAAU,KAAK,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,CAAC;AACxD;AAOO,MAAM,k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M;AAErD,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,2BAAa,kBAAkB,EAAE,OAAO,CAAC;AAAA,EACrD;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/services/user.service.ts"],"sourcesContent":["import type { User, UserAPI, UserDocument } from '@/types/user.types';\nimport { UserModel } from '@models/user.model';\nimport { GenericError } from '@utils/errors';\nimport type { UserFilters } from '@utils/filtersAndPagination/getUserFiltersAndPagination';\nimport {\n type FieldsToCheck,\n type UserFields,\n validateUser,\n} from '@utils/validation/validateUser';\nimport type { Types } from 'mongoose';\n\n/**\n * Creates a new user with password in the database and hashes the password.\n * @param user - User object with password not hashed.\n * @returns Created user object.\n */\nexport const createUser = async (\n user: Partial<User>\n): Promise<UserDocument> => {\n const fieldsToCheck: FieldsToCheck[] = ['email'];\n\n const errors = validateUser(user, fieldsToCheck);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('USER_INVALID_FIELDS', {\n userEmail: user.email,\n errors,\n });\n }\n\n const newUser: UserDocument = await UserModel.create(user);\n\n if (!newUser) {\n throw new GenericError('USER_CREATION_FAILED', { userEmail: user.email });\n }\n\n return newUser;\n};\n\n/**\n * Retrieves a user by email.\n * @param email - User's email.\n * @returns User object or null if no user was found.\n */\nexport const getUserByEmail = async (\n email: string\n): Promise<UserDocument | null> => {\n return await UserModel.findOne({ email });\n};\n\n/**\n * Retrieves users list by email.\n * @param emails - Users email.\n * @returns User object or null if no user was found.\n */\nexport const getUsersByEmails = async (\n emails: string[]\n): Promise<UserDocument[] | null> => {\n return await UserModel.find({ email: { $in: emails } });\n};\n\n/**\n * Checks if a user exists by email.\n * @param email - User's email.\n * @returns True if the user exists, false otherwise.\n */\nexport const checkUserExists = async (email: string): Promise<boolean> => {\n const user = await UserModel.exists({ email });\n return user !== null;\n};\n\n/**\n * Retrieves a user by ID.\n * @param userId - User's ID.\n * @returns User object or null if no user was found.\n */\nexport const getUserById = async (\n userId: string | Types.ObjectId\n): Promise<UserDocument | null> => await UserModel.findById(userId);\n\n/**\n * Retrieves a user by ID.\n * @param userId - User's ID.\n * @returns User object or null if no user was found.\n */\nexport const getUsersByIds = async (\n userIds: (string | Types.ObjectId)[]\n): Promise<UserDocument[] | null> =>\n await UserModel.find({ _id: { $in: userIds } });\n\n/**\n * Finds users based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of users matching the filters.\n */\nexport const findUsers = async (\n filters: UserFilters,\n skip: number,\n limit: number\n): Promise<UserDocument[]> => {\n return await UserModel.find(filters).skip(skip).limit(limit);\n};\n\n/**\n * Counts the total number of users that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of users.\n */\nexport const countUsers = async (filters: UserFilters): Promise<number> => {\n const count = await UserModel.countDocuments(filters);\n\n if (typeof count === 'undefined') {\n throw new GenericError('USER_COUNT_FAILED');\n }\n\n return count;\n};\n\n/**\n * Updates a user's information.\n * @param user - The user object.\n * @param updates - The updates to apply to the user.\n * @returns The updated user.\n */\nexport const updateUserById = async (\n userId: string | Types.ObjectId,\n updates: Partial<UserAPI>\n): Promise<UserDocument> => {\n const keyToValidate = Object.keys(updates) as UserFields;\n const errors = validateUser(updates, keyToValidate);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('USER_INVALID_FIELDS', {\n userId,\n errors,\n });\n }\n\n const result = await UserModel.updateOne({ _id: userId }, { $set: updates });\n\n if (result.matchedCount === 0) {\n throw new GenericError('USER_UPDATE_FAILED', { userId });\n }\n\n const updatedUser = await UserModel.findById(userId);\n\n if (!updatedUser) {\n throw new GenericError('USER_UPDATED_USER_NOT_FOUND', { userId });\n }\n\n return updatedUser;\n};\n\n/**\n * Deletes a user from the database.\n * @param userId - The user object.\n * @returns\n */\nexport const deleteUser = async (\n userId: string | Types.ObjectId\n): Promise<UserDocument> => {\n await getUserById(userId);\n\n const user = await UserModel.findByIdAndDelete(userId);\n\n if (!user) {\n throw new GenericError('USER_NOT_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,QAAM,QAAQ,MAAM,sBAAU,eAAe,OAAO;AAEpD,MAAI,OAAO,UAAU,aAAa;AAChC,UAAM,IAAI,2BAAa,mBAAmB;AAAA,EAC5C;AAEA,SAAO;AACT;AAQO,MAAM,iBAAiB,OAC5B,QACA,YAC0B;AAC1B,QAAM,gBAAgB,OAAO,KAAK,OAAO;AACzC,QAAM,aAAS,kCAAa,SAAS,aAAa;AAElD,MAAI,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAClC,UAAM,IAAI,2BAAa,uBAAuB;AAAA,MAC5C;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,SAAS,MAAM,sBAAU,UAAU,EAAE,KAAK,OAAO,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE3E,MAAI,OAAO,iBAAiB,GAAG;AAC7B,UAAM,IAAI,2BAAa,sBAAsB,EAAE,OAAO,CAAC;AAAA,EACzD;AAEA,QAAM,cAAc,MAAM,sBAAU,SAAS,MAAM;AAEnD,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI,2BAAa,+BAA+B,EAAE,OAAO,CAAC;AAAA,EAClE;AAEA,SAAO;AACT;AAOO,MAAM,aAAa,OACxB,WAC0B;AAC1B,QAAM,YAAY,MAAM;AAExB,QAAM,OAAO,MAAM,sBAAU,kBAAkB,MAAM;AAErD,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,2BAAa,kBAAkB,EAAE,OAAO,CAAC;AAAA,EACrD;AAEA,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/dictionary.types.ts"],"sourcesContent":["import {\n type ContentNode,\n type Dictionary as DictionaryCore,\n} from '@intlayer/core';\nimport { RenameId } from '@utils/mongoDB/types';\nimport type { Document, Model, ObjectIdToString, Types } from 'mongoose';\nimport type { Project } from './project.types';\nimport type { User } from './user.types';\n\nexport type DictionaryCreationData = {\n projectIds: (Project['id'] | string)[];\n key: string;\n content?: ContentNode;\n title?: string;\n description?: string;\n tags?: string[];\n filePath?: string;\n};\n\nexport type VersionedContentEl = {\n name?: string;\n description?: string;\n content: ContentNode;\n};\n\nexport type ContentVersion = string;\nexport type VersionedContent = Map<string, VersionedContentEl>;\n\nexport type DictionaryData = {\n key: string;\n content: VersionedContent;\n projectIds: (Project['id'] | string)[];\n creatorId: User['id'];\n title?: string;\n description?: string;\n tags?: string[];\n filePath?: Record<string, string>;\n};\n\nexport type Dictionary = DictionaryData & {\n id: Types.ObjectId;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type DictionaryAPI = ObjectIdToString<\n DictionaryCore & {\n projectIds: (Project['id'] | string)[];\n }\n>;\n\nexport type DictionarySchema = RenameId<Dictionary>;\nexport type DictionaryModelType = Model<Dictionary>;\nexport type DictionaryDocument = Document<unknown, {}, Dictionary> & Dictionary;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/types/dictionary.types.ts"],"sourcesContent":["import {\n type ContentNode,\n type Dictionary as DictionaryCore,\n} from '@intlayer/core';\nimport { RenameId } from '@utils/mongoDB/types';\nimport type { Document, Model, ObjectIdToString, Types } from 'mongoose';\nimport type { Project } from './project.types';\nimport type { User } from './user.types';\n\nexport type DictionaryCreationData = {\n projectIds: (Project['id'] | string)[];\n key: string;\n content?: ContentNode;\n title?: string;\n description?: string;\n priority?: number;\n live?: boolean;\n tags?: string[];\n};\n\nexport type VersionedContentEl = {\n name?: string;\n description?: string;\n content: ContentNode;\n};\n\nexport type ContentVersion = string;\nexport type VersionedContent = Map<string, VersionedContentEl>;\n\nexport type DictionaryData = {\n key: string;\n content: VersionedContent;\n projectIds: (Project['id'] | string)[];\n creatorId: User['id'];\n title?: string;\n description?: string;\n priority?: number;\n live?: boolean;\n tags?: string[];\n};\n\nexport type Dictionary = DictionaryData & {\n id: Types.ObjectId;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type DictionaryAPI = ObjectIdToString<\n DictionaryCore & {\n projectIds: (Project['id'] | string)[];\n }\n>;\n\nexport type DictionarySchema = RenameId<Dictionary>;\nexport type DictionaryModelType = Model<Dictionary>;\nexport type DictionaryDocument = Document<unknown, {}, Dictionary> & Dictionary;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/plan.types.ts"],"sourcesContent":["import type { RenameId } from '@utils/mongoDB/types';\nimport type { Document, Model, Types } from 'mongoose';\nimport type { User } from './user.types';\n\nexport type PlanType = 'FREE' | 'PREMIUM' | 'ENTERPRISE';\n\nexport type PlanData = {\n type: PlanType;\n creatorId?: User['id'];\n subscriptionId?: string;\n customerId?: string;\n priceId?: string;\n status?:\n | 'active'\n | 'canceled'\n | 'past_due'\n | 'unpaid'\n | 'incomplete'\n | 'incomplete_expired'\n | 'paused'\n | 'trialing';\n period?: 'MONTHLY' | 'YEARLY';\n};\n\nexport type Plan = PlanData & {\n id: Types.ObjectId;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type PlanSchema = RenameId<Plan>;\nexport type PlanModelType = Model<Plan>;\nexport type PlanDocument = Document<unknown, {}, Plan> & Plan;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/types/plan.types.ts"],"sourcesContent":["import type { RenameId } from '@utils/mongoDB/types';\nimport type { Document, Model, ObjectIdToString, Types } from 'mongoose';\nimport type { User } from './user.types';\n\nexport type PlanType = 'FREE' | 'PREMIUM' | 'ENTERPRISE';\n\nexport type PlanData = {\n type: PlanType;\n creatorId?: User['id'];\n subscriptionId?: string;\n customerId?: string;\n priceId?: string;\n status?:\n | 'active'\n | 'canceled'\n | 'past_due'\n | 'unpaid'\n | 'incomplete'\n | 'incomplete_expired'\n | 'paused'\n | 'trialing';\n period?: 'MONTHLY' | 'YEARLY';\n};\n\nexport type Plan = PlanData & {\n id: Types.ObjectId;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type PlanAPI = ObjectIdToString<Plan>;\n\nexport type PlanSchema = RenameId<Plan>;\nexport type PlanModelType = Model<Plan>;\nexport type PlanDocument = Document<unknown, {}, Plan> & Plan;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/project.types.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/config';\nimport { RenameId } from '@utils/mongoDB/types';\nimport type { Document, Model, ObjectIdToString, Types } from 'mongoose';\nimport { Token } from 'oauth2-server';\nimport type { Organization, OrganizationAPI } from './organization.types';\nimport type { User, UserAPI } from './user.types';\n\nexport type ProjectCreationData = {\n name: Project['name'];\n};\n\ntype ProjectConfigInternationalization = Pick<\n IntlayerConfig['internationalization'],\n 'locales' | 'defaultLocale'\n>;\n\ntype ProjectConfigEditor = Pick<\n IntlayerConfig['editor'],\n 'applicationURL' | 'cmsURL'\n>;\n\nexport type ProjectConfiguration = {\n internationalization: ProjectConfigInternationalization;\n editor: ProjectConfigEditor;\n};\n\nexport type ProjectData = {\n organizationId: Organization['id'];\n name: string;\n membersIds: User['id'][];\n adminsIds: User['id'][];\n creatorId: User['id'];\n configuration?: ProjectConfiguration;\n};\n\nexport type AccessKeyData = {\n name: string;\n grants: string[];\n expiresAt?: Date;\n};\n\nexport type OAuth2AccessData = AccessKeyData & {\n clientId: string;\n clientSecret: string;\n accessToken: string[];\n userId: User['id'];\n};\n\nexport type OAuth2AccessContext = {\n accessToken: Token;\n user?: UserAPI;\n project?: ProjectAPI;\n organization?: OrganizationAPI;\n grants: Token['grants'];\n};\n\nexport type OAuth2Access = OAuth2AccessData & {\n id: Types.ObjectId;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type Project = ProjectData & {\n id: Types.ObjectId;\n createdAt: number;\n updatedAt: number;\n oAuth2Access: OAuth2Access[];\n};\n\nexport type ProjectAPI = ObjectIdToString<Project>;\n\nexport type ProjectSchema = RenameId<Project>;\nexport type ProjectModelType = Model<Project>;\nexport type ProjectDocument = Document<unknown, {}, Project> & Project;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/types/project.types.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/config';\nimport { RenameId } from '@utils/mongoDB/types';\nimport type { Document, Model, ObjectIdToString, Types } from 'mongoose';\nimport { Token } from 'oauth2-server';\nimport type { Organization, OrganizationAPI } from './organization.types';\nimport type { User, UserAPI } from './user.types';\n\nexport type ProjectCreationData = {\n name: Project['name'];\n};\n\ntype ProjectConfigInternationalization = Pick<\n IntlayerConfig['internationalization'],\n 'locales' | 'defaultLocale'\n>;\n\ntype ProjectConfigEditor = Pick<\n IntlayerConfig['editor'],\n 'applicationURL' | 'cmsURL'\n>;\n\nexport type ProjectConfiguration = {\n internationalization: ProjectConfigInternationalization;\n editor: ProjectConfigEditor;\n};\n\nexport type ProjectData = {\n organizationId: Organization['id'];\n name: string;\n membersIds: User['id'][];\n adminsIds: User['id'][];\n creatorId: User['id'];\n configuration?: ProjectConfiguration;\n};\n\nexport type AccessKeyData = {\n name: string;\n grants: string[];\n expiresAt?: Date;\n};\n\nexport type OAuth2AccessData = AccessKeyData & {\n clientId: string;\n clientSecret: string;\n accessToken: string[];\n userId: User['id'];\n};\n\nexport type OAuth2AccessContext = {\n accessToken: Token;\n user?: UserAPI;\n project?: ProjectAPI;\n organization?: OrganizationAPI;\n grants: Token['grants'];\n};\n\nexport type OAuth2Access = OAuth2AccessData & {\n id: Types.ObjectId;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type OAuth2AccessAPI = ObjectIdToString<OAuth2Access>;\n\nexport type Project = ProjectData & {\n id: Types.ObjectId;\n createdAt: number;\n updatedAt: number;\n oAuth2Access: OAuth2Access[];\n};\n\nexport type ProjectAPI = ObjectIdToString<Project>;\n\nexport type ProjectSchema = RenameId<Project>;\nexport type ProjectModelType = Model<Project>;\nexport type ProjectDocument = Document<unknown, {}, Project> & Project;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/utils/AI/aiSdk.ts"],"sourcesContent":["import { anthropic, createAnthropic } from '@ai-sdk/anthropic';\nimport { createDeepSeek, deepseek } from '@ai-sdk/deepseek';\nimport { createGoogleGenerativeAI, google } from '@ai-sdk/google';\nimport { createMistral, mistral } from '@ai-sdk/mistral';\nimport { createOpenAI, openai } from '@ai-sdk/openai';\nimport {\n AssistantModelMessage,\n generateText,\n SystemModelMessage,\n ToolModelMessage,\n UserModelMessage,\n} from 'ai';\nimport { Response } from 'express';\n\ntype AnthropicModel = Parameters<typeof anthropic>[0];\ntype DeepSeekModel = Parameters<typeof deepseek>[0];\ntype MistralModel = Parameters<typeof mistral>[0];\ntype OpenAIModel = Parameters<typeof openai>[0];\ntype GoogleModel = Parameters<typeof google>[0];\n\nexport type Messages = (\n | SystemModelMessage\n | UserModelMessage\n | AssistantModelMessage\n | ToolModelMessage\n)[];\n\n/**\n * Supported AI models\n */\nexport type Model =\n | AnthropicModel\n | DeepSeekModel\n | MistralModel\n | OpenAIModel\n | GoogleModel\n | (string & {});\n\n/**\n * Supported AI SDK providers\n */\nexport enum AIProvider {\n OPENAI = 'openai',\n ANTHROPIC = 'anthropic',\n MISTRAL = 'mistral',\n DEEPSEEK = 'deepseek',\n GEMINI = 'gemini',\n}\n\n/**\n * Common options for all AI providers\n */\nexport type AIOptions = {\n provider?: AIProvider;\n model?: Model;\n temperature?: number;\n apiKey?: string;\n applicationContext?: string;\n};\n\n// Define the structure of messages used in chat completions\nexport type ChatCompletionRequestMessage = {\n role: 'system' | 'user' | 'assistant'; // The role of the message sender\n content: string; // The text content of the message\n timestamp?: Date; // The timestamp of the message\n};\n\ntype AccessType = 'apiKey' | 'registered_user' | 'premium_user' | 'public';\n\nconst getAPIKey = (\n res: Response,\n accessType: AccessType[],\n aiOptions?: AIOptions\n) => {\n const defaultApiKey = process.env.OPENAI_API_KEY;\n\n if (accessType.includes('public')) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n if (accessType.includes('apiKey') && aiOptions?.apiKey) {\n return aiOptions?.apiKey;\n }\n\n if (accessType.includes('registered_user') && res.locals.user) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n // TODO: Implement premium user access\n if (accessType.includes('premium_user') && res.locals.user) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n return undefined;\n};\n\nconst getModel = (\n provider: AIProvider,\n userApiKey: string,\n userModel?: Model,\n defaultModel?: Model\n): Model => {\n // Set default models based on provider\n let fallBackModel: Model = defaultModel ?? 'chatgpt-4o-latest';\n\n switch (provider) {\n case AIProvider.OPENAI:\n defaultModel = 'chatgpt-4o-latest';\n break;\n case AIProvider.ANTHROPIC:\n defaultModel = 'claude-3-haiku-20240307';\n break;\n case AIProvider.MISTRAL:\n defaultModel = 'mistral-large-latest';\n break;\n case AIProvider.DEEPSEEK:\n defaultModel = 'deepseek-coder';\n break;\n case AIProvider.GEMINI:\n defaultModel = 'gemini-1.5-pro';\n break;\n }\n\n // If the user use his own API, let him use the model he wants\n if (Boolean(userApiKey) && Boolean(userModel)) {\n return userModel!;\n }\n\n if (Boolean(userModel)) {\n throw new Error(\n 'The user should use his own API key to use a custom model'\n );\n }\n\n return fallBackModel;\n};\n\nexport type AIConfig = Parameters<typeof generateText>[0];\n\nconst DEFAULT_PROVIDER: AIProvider = AIProvider.OPENAI as AIProvider;\nconst DEFAULT_TEMPERATURE: number = 1; // ChatGPT 5 accept only temperature 1\n\nexport type AIConfigOptions = {\n userOptions?: AIOptions;\n defaultOptions?: AIOptions;\n accessType?: AccessType[];\n};\n\n/**\n * Get AI model configuration based on the selected provider and options\n * This function handles the configuration for different AI providers\n *\n * @param options Configuration options including provider, API keys, models and temperature\n * @returns Configured AI model ready to use with generateText\n */\nexport const getAIConfig = async (\n res: Response,\n options: AIConfigOptions\n): Promise<AIConfig> => {\n const {\n userOptions,\n defaultOptions,\n accessType = ['registered_user'],\n } = options;\n\n const aiOptions = {\n provider: DEFAULT_PROVIDER,\n temperature: DEFAULT_TEMPERATURE,\n ...defaultOptions,\n ...userOptions,\n } satisfies AIOptions;\n\n const apiKey = getAPIKey(res, accessType, aiOptions);\n\n // Check if API key is provided\n if (!apiKey) {\n throw new Error(`API key for ${aiOptions.provider} is missing`);\n }\n\n const selectedModel = getModel(\n aiOptions.provider,\n apiKey,\n aiOptions.model,\n defaultOptions?.model\n );\n\n const protectedOptions = {\n ...aiOptions,\n apiKey,\n model: selectedModel,\n } satisfies AIOptions;\n\n let languageModel: AIConfig['model'];\n\n switch (protectedOptions.provider) {\n case AIProvider.OPENAI: {\n languageModel = createOpenAI({\n apiKey,\n })(selectedModel);\n break;\n }\n\n case AIProvider.ANTHROPIC: {\n languageModel = createAnthropic({\n apiKey,\n })(selectedModel);\n break;\n }\n\n case AIProvider.MISTRAL: {\n languageModel = createMistral({\n apiKey,\n })(selectedModel);\n break;\n }\n\n case AIProvider.DEEPSEEK: {\n languageModel = createDeepSeek({\n apiKey,\n })(selectedModel);\n break;\n }\n\n case AIProvider.GEMINI: {\n languageModel = createGoogleGenerativeAI({\n apiKey,\n })(selectedModel);\n break;\n }\n\n default: {\n throw new Error(`Provider ${protectedOptions.provider} not supported`);\n }\n }\n\n return {\n model: languageModel,\n temperature: protectedOptions.temperature,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA2C;AAC3C,sBAAyC;AACzC,oBAAiD;AACjD,qBAAuC;AACvC,oBAAqC;AAqC9B,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,YAAS;AACT,EAAAA,YAAA,eAAY;AACZ,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,YAAS;AALC,SAAAA;AAAA,GAAA;AA4BZ,MAAM,YAAY,CAChB,KACA,YACA,cACG;AACH,QAAM,gBAAgB,QAAQ,IAAI;AAElC,MAAI,WAAW,SA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ACA,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AAEA,QAAM,mBAAmB;AAAA,IACvB,GAAG;AAAA,IACH;AAAA,IACA,OAAO;AAAA,EACT;AAEA,MAAI;AAEJ,UAAQ,iBAAiB,UAAU;AAAA,IACjC,KAAK,uBAAmB;AACtB,0BAAgB,4BAAa;AAAA,QAC3B;AAAA,MACF,CAAC,EAAE,aAAa;AAChB;AAAA,IACF;AAAA,IAEA,KAAK,6BAAsB;AACzB,0BAAgB,kCAAgB;AAAA,QAC9B;AAAA,MACF,CAAC,EAAE,aAAa;AAChB;AAAA,IACF;AAAA,IAEA,KAAK,yBAAoB;AACvB,0BAAgB,8BAAc;AAAA,QAC5B;AAAA,MACF,CAAC,EAAE,aAAa;AAChB;AAAA,IACF;AAAA,IAEA,KAAK,2BAAqB;AACxB,0BAAgB,gCAAe;AAAA,QAC7B;AAAA,MACF,CAAC,EAAE,aAAa;AAChB;AAAA,IACF;AAAA,IAEA,KAAK,uBAAmB;AACtB,0BAAgB,wCAAyB;AAAA,QACvC;AAAA,MACF,CAAC,EAAE,aAAa;AAChB;AAAA,IACF;AAAA,IAEA,SAAS;AACP,YAAM,IAAI,MAAM,YAAY,iBAAiB,QAAQ,gBAAgB;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,IACP,aAAa,iBAAiB;AAAA,EAChC;AACF;","names":["AIProvider"]}
1
+ {"version":3,"sources":["../../../../src/utils/AI/aiSdk.ts"],"sourcesContent":["import { anthropic, createAnthropic } from '@ai-sdk/anthropic';\nimport { createDeepSeek, deepseek } from '@ai-sdk/deepseek';\nimport { createGoogleGenerativeAI, google } from '@ai-sdk/google';\nimport { createMistral, mistral } from '@ai-sdk/mistral';\nimport { createOpenAI, openai } from '@ai-sdk/openai';\nimport {\n AssistantModelMessage,\n generateText,\n SystemModelMessage,\n ToolModelMessage,\n UserModelMessage,\n} from 'ai';\nimport { Response } from 'express';\n\ntype AnthropicModel = Parameters<typeof anthropic>[0];\ntype DeepSeekModel = Parameters<typeof deepseek>[0];\ntype MistralModel = Parameters<typeof mistral>[0];\ntype OpenAIModel = Parameters<typeof openai>[0];\ntype GoogleModel = Parameters<typeof google>[0];\n\nexport type Messages = (\n | SystemModelMessage\n | UserModelMessage\n | AssistantModelMessage\n | ToolModelMessage\n)[];\n\n/**\n * Supported AI models\n */\nexport type Model =\n | AnthropicModel\n | DeepSeekModel\n | MistralModel\n | OpenAIModel\n | GoogleModel\n | (string & {});\n\n/**\n * Supported AI SDK providers\n */\nexport enum AIProvider {\n OPENAI = 'openai',\n ANTHROPIC = 'anthropic',\n MISTRAL = 'mistral',\n DEEPSEEK = 'deepseek',\n GEMINI = 'gemini',\n}\n\n/**\n * Common options for all AI providers\n */\nexport type AIOptions = {\n provider?: AIProvider;\n model?: Model;\n temperature?: number;\n apiKey?: string;\n applicationContext?: string;\n};\n\n// Define the structure of messages used in chat completions\nexport type ChatCompletionRequestMessage = {\n role: 'system' | 'user' | 'assistant'; // The role of the message sender\n content: string; // The text content of the message\n timestamp?: Date; // The timestamp of the message\n};\n\ntype AccessType = 'apiKey' | 'registered_user' | 'premium_user' | 'public';\n\nconst getAPIKey = (\n res: Response,\n accessType: AccessType[],\n aiOptions?: AIOptions\n) => {\n const defaultApiKey = process.env.OPENAI_API_KEY;\n\n if (accessType.includes('public')) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n if (accessType.includes('apiKey') && aiOptions?.apiKey) {\n return aiOptions?.apiKey;\n }\n\n if (accessType.includes('registered_user') && res.locals.user) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n // TODO: Implement premium user access\n if (accessType.includes('premium_user') && res.locals.user) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n return undefined;\n};\n\nconst getModel = (\n provider: AIProvider,\n userApiKey: string,\n userModel?: Model,\n defaultModel?: Model\n): Model => {\n // Set default models based on provider\n let fallBackModel: Model = defaultModel ?? 'chatgpt-4o-latest';\n\n switch (provider) {\n case AIProvider.OPENAI:\n defaultModel = 'chatgpt-4o-latest';\n break;\n case AIProvider.ANTHROPIC:\n defaultModel = 'claude-3-haiku-20240307';\n break;\n case AIProvider.MISTRAL:\n defaultModel = 'mistral-large-latest';\n break;\n case AIProvider.DEEPSEEK:\n defaultModel = 'deepseek-coder';\n break;\n case AIProvider.GEMINI:\n defaultModel = 'gemini-1.5-pro';\n break;\n }\n\n // If the user use his own API, let him use the model he wants\n if (Boolean(userApiKey) && Boolean(userModel)) {\n return userModel!;\n }\n\n if (Boolean(userModel)) {\n throw new Error(\n 'The user should use his own API key to use a custom model'\n );\n }\n\n return fallBackModel;\n};\n\nexport type AIConfig = Omit<Parameters<typeof generateText>[0], 'prompt'>;\n\nconst DEFAULT_PROVIDER: AIProvider = AIProvider.OPENAI as AIProvider;\nconst DEFAULT_TEMPERATURE: number = 1; // ChatGPT 5 accept only temperature 1\n\nexport type AIConfigOptions = {\n userOptions?: AIOptions;\n defaultOptions?: AIOptions;\n accessType?: AccessType[];\n};\n\n/**\n * Get AI model configuration based on the selected provider and options\n * This function handles the configuration for different AI providers\n *\n * @param options Configuration options including provider, API keys, models and temperature\n * @returns Configured AI model ready to use with generateText\n */\nexport const getAIConfig = async (\n res: Response,\n options: AIConfigOptions\n): Promise<AIConfig> => {\n const {\n userOptions,\n defaultOptions,\n accessType = ['registered_user'],\n } = options;\n\n const aiOptions = {\n provider: DEFAULT_PROVIDER,\n temperature: DEFAULT_TEMPERATURE,\n ...defaultOptions,\n ...userOptions,\n } satisfies AIOptions;\n\n const apiKey = getAPIKey(res, accessType, aiOptions);\n\n // Check if API key is provided\n if (!apiKey) {\n throw new Error(`API key for ${aiOptions.provider} is missing`);\n }\n\n const selectedModel = getModel(\n aiOptions.provider,\n apiKey,\n aiOptions.model,\n defaultOptions?.model\n );\n\n const protectedOptions = {\n ...aiOptions,\n apiKey,\n model: selectedModel,\n } satisfies AIOptions;\n\n let languageModel: AIConfig['model'];\n\n switch (protectedOptions.provider) {\n case AIProvider.OPENAI: {\n languageModel = createOpenAI({\n apiKey,\n })(selectedModel);\n break;\n }\n\n case AIProvider.ANTHROPIC: {\n languageModel = createAnthropic({\n apiKey,\n })(selectedModel);\n break;\n }\n\n case AIProvider.MISTRAL: {\n languageModel = createMistral({\n apiKey,\n })(selectedModel);\n break;\n }\n\n case AIProvider.DEEPSEEK: {\n languageModel = createDeepSeek({\n apiKey,\n })(selectedModel);\n break;\n }\n\n case AIProvider.GEMINI: {\n languageModel = createGoogleGenerativeAI({\n apiKey,\n })(selectedModel);\n break;\n }\n\n default: {\n throw new Error(`Provider ${protectedOptions.provider} not supported`);\n }\n }\n\n return {\n model: languageModel,\n temperature: protectedOptions.temperature,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA2C;AAC3C,sBAAyC;AACzC,oBAAiD;AACjD,qBAAuC;AACvC,oBAAqC;AAqC9B,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,YAAS;AACT,EAAAA,YAAA,eAAY;AACZ,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,YAAS;AALC,SAAAA;AAAA,GAAA;AA4BZ,MAAM,YAAY,CAChB,KACA,YACA,cACG;AACH,QAAM,gBAAgB,QAAQ,IAAI;AAElC,MAAI,WAAW,SAAS,QAAQ,GAAG;AACjC,WAAO,WAAW,UAAU;AAAA,EAC9B;AAEA,MAAI,WAAW,SAAS,QAAQ,KAAK,WAAW,QAAQ;AACtD,WAAO,WAAW;AAAA,EACpB;AAEA,MAAI,WAAW,SAAS,iBAAiB,KAAK,IAAI,OAAO,MAAM;AAC7D,WAAO,WAAW,UAAU;AAAA,EAC9B;AAGA,MAAI,WAAW,SAAS,cAAc,KAAK,IAAI,OAAO,MAAM;AAC1D,WAAO,WAAW,UAAU;AAAA,EAC9B;AAEA,SAAO;AACT;AAEA,MAAM,WAAW,CACf,UACA,YACA,W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;AAAA,IAEA,KAAK,yBAAoB;AACvB,0BAAgB,8BAAc;AAAA,QAC5B;AAAA,MACF,CAAC,EAAE,aAAa;AAChB;AAAA,IACF;AAAA,IAEA,KAAK,2BAAqB;AACxB,0BAAgB,gCAAe;AAAA,QAC7B;AAAA,MACF,CAAC,EAAE,aAAa;AAChB;AAAA,IACF;AAAA,IAEA,KAAK,uBAAmB;AACtB,0BAAgB,wCAAyB;AAAA,QACvC;AAAA,MACF,CAAC,EAAE,aAAa;AAChB;AAAA,IACF;AAAA,IAEA,SAAS;AACP,YAAM,IAAI,MAAM,YAAY,iBAAiB,QAAQ,gBAAgB;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,IACP,aAAa,iBAAiB;AAAA,EAChC;AACF;","names":["AIProvider"]}
@@ -62,6 +62,7 @@ const MAX_CHUNK_TOKENS = 800;
62
62
  const CHAR_BY_TOKEN = 4.15;
63
63
  const MAX_CHARS = MAX_CHUNK_TOKENS * CHAR_BY_TOKEN;
64
64
  const OVERLAP_CHARS = OVERLAP_TOKENS * CHAR_BY_TOKEN;
65
+ const skipDocEmbeddingsIndex = process.env.SKIP_DOC_EMBEDDINGS_INDEX === "true";
65
66
  const chunkText = (text) => {
66
67
  const chunks = [];
67
68
  let start = 0;
@@ -130,7 +131,7 @@ const indexMarkdownFiles = async () => {
130
131
  console.info(
131
132
  `File "${fileKey}" chunk count changed: ${previousChunkCount} -> ${currentChunkCount}. Regenerating embeddings.`
132
133
  );
133
- shouldRegenerateFileEmbeddings = true;
134
+ shouldRegenerateFileEmbeddings = !skipDocEmbeddingsIndex;
134
135
  }
135
136
  for await (const chunkIndex of Object.keys(fileChunks)) {
136
137
  const chunkNumber = Number(chunkIndex) + 1;