@intlayer/backend 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/dist/cjs/controllers/dictionary.controller.cjs +356 -0
- package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -0
- package/dist/cjs/controllers/oAuth2.controller.cjs +46 -0
- package/dist/cjs/controllers/oAuth2.controller.cjs.map +1 -0
- package/dist/cjs/controllers/organization.controller.cjs +354 -0
- package/dist/cjs/controllers/organization.controller.cjs.map +1 -0
- package/dist/cjs/controllers/project.controller.cjs +298 -0
- package/dist/cjs/controllers/project.controller.cjs.map +1 -0
- package/dist/cjs/controllers/projectAccessKey.controller.cjs +134 -0
- package/dist/cjs/controllers/projectAccessKey.controller.cjs.map +1 -0
- package/dist/cjs/controllers/sessionAuth.controller.cjs +616 -0
- package/dist/cjs/controllers/sessionAuth.controller.cjs.map +1 -0
- package/dist/cjs/controllers/user.controller.cjs +197 -0
- package/dist/cjs/controllers/user.controller.cjs.map +1 -0
- package/dist/cjs/emails/InviteUserEmail.cjs +297 -0
- package/dist/cjs/emails/InviteUserEmail.cjs.map +1 -0
- package/dist/cjs/emails/PasswordChangeConfirmation.cjs +148 -0
- package/dist/cjs/emails/PasswordChangeConfirmation.cjs.map +1 -0
- package/dist/cjs/emails/ResetUserPassword.cjs +209 -0
- package/dist/cjs/emails/ResetUserPassword.cjs.map +1 -0
- package/dist/cjs/emails/ValidateUserEmail.cjs +230 -0
- package/dist/cjs/emails/ValidateUserEmail.cjs.map +1 -0
- package/dist/cjs/emails/Welcome.cjs +185 -0
- package/dist/cjs/emails/Welcome.cjs.map +1 -0
- package/dist/cjs/emails/index.cjs +31 -0
- package/dist/cjs/emails/index.cjs.map +1 -0
- package/dist/cjs/export.cjs +46 -0
- package/dist/cjs/export.cjs.map +1 -0
- package/dist/cjs/index.cjs +122 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/logger/index.cjs +53 -0
- package/dist/cjs/logger/index.cjs.map +1 -0
- package/dist/cjs/middlewares/admin.middleware.cjs +44 -0
- package/dist/cjs/middlewares/admin.middleware.cjs.map +1 -0
- package/dist/cjs/middlewares/oAuth2.middleware.cjs +89 -0
- package/dist/cjs/middlewares/oAuth2.middleware.cjs.map +1 -0
- package/dist/cjs/middlewares/request.middleware.cjs +41 -0
- package/dist/cjs/middlewares/request.middleware.cjs.map +1 -0
- package/dist/cjs/middlewares/sessionAuth.middleware.cjs +130 -0
- package/dist/cjs/middlewares/sessionAuth.middleware.cjs.map +1 -0
- package/dist/cjs/models/dictionary.model.cjs +34 -0
- package/dist/cjs/models/dictionary.model.cjs.map +1 -0
- package/dist/cjs/models/oAuth2.model.cjs +31 -0
- package/dist/cjs/models/oAuth2.model.cjs.map +1 -0
- package/dist/cjs/models/organization.model.cjs +34 -0
- package/dist/cjs/models/organization.model.cjs.map +1 -0
- package/dist/cjs/models/project.model.cjs +31 -0
- package/dist/cjs/models/project.model.cjs.map +1 -0
- package/dist/cjs/models/user.model.cjs +31 -0
- package/dist/cjs/models/user.model.cjs.map +1 -0
- package/dist/cjs/routes/dictionary.routes.cjs +156 -0
- package/dist/cjs/routes/dictionary.routes.cjs.map +1 -0
- package/dist/cjs/routes/organization.routes.cjs +132 -0
- package/dist/cjs/routes/organization.routes.cjs.map +1 -0
- package/dist/cjs/routes/project.routes.cjs +175 -0
- package/dist/cjs/routes/project.routes.cjs.map +1 -0
- package/dist/cjs/routes/sessionAuth.routes.cjs +147 -0
- package/dist/cjs/routes/sessionAuth.routes.cjs.map +1 -0
- package/dist/cjs/routes/user.routes.cjs +96 -0
- package/dist/cjs/routes/user.routes.cjs.map +1 -0
- package/dist/cjs/schemas/dictionary.schema.cjs +69 -0
- package/dist/cjs/schemas/dictionary.schema.cjs.map +1 -0
- package/dist/cjs/schemas/oAuth2.schema.cjs +55 -0
- package/dist/cjs/schemas/oAuth2.schema.cjs.map +1 -0
- package/dist/cjs/schemas/organization.schema.cjs +60 -0
- package/dist/cjs/schemas/organization.schema.cjs.map +1 -0
- package/dist/cjs/schemas/project.schema.cjs +79 -0
- package/dist/cjs/schemas/project.schema.cjs.map +1 -0
- package/dist/cjs/schemas/user.schema.cjs +112 -0
- package/dist/cjs/schemas/user.schema.cjs.map +1 -0
- package/dist/cjs/services/dictionary.service.cjs +166 -0
- package/dist/cjs/services/dictionary.service.cjs.map +1 -0
- package/dist/cjs/services/email.service.cjs +118 -0
- package/dist/cjs/services/email.service.cjs.map +1 -0
- package/dist/cjs/services/oAuth2.service.cjs +182 -0
- package/dist/cjs/services/oAuth2.service.cjs.map +1 -0
- package/dist/cjs/services/organization.service.cjs +95 -0
- package/dist/cjs/services/organization.service.cjs.map +1 -0
- package/dist/cjs/services/project.service.cjs +87 -0
- package/dist/cjs/services/project.service.cjs.map +1 -0
- package/dist/cjs/services/projectAccessKey.service.cjs +139 -0
- package/dist/cjs/services/projectAccessKey.service.cjs.map +1 -0
- package/dist/cjs/services/sessionAuth.service.cjs +386 -0
- package/dist/cjs/services/sessionAuth.service.cjs.map +1 -0
- package/dist/cjs/services/user.service.cjs +155 -0
- package/dist/cjs/services/user.service.cjs.map +1 -0
- package/dist/cjs/types/Routes.cjs +17 -0
- package/dist/cjs/types/Routes.cjs.map +1 -0
- package/dist/cjs/types/dictionary.types.cjs +17 -0
- package/dist/cjs/types/dictionary.types.cjs.map +1 -0
- package/dist/cjs/types/organization.types.cjs +17 -0
- package/dist/cjs/types/organization.types.cjs.map +1 -0
- package/dist/cjs/types/project.types.cjs +17 -0
- package/dist/cjs/types/project.types.cjs.map +1 -0
- package/dist/cjs/types/session.types.cjs +17 -0
- package/dist/cjs/types/session.types.cjs.map +1 -0
- package/dist/cjs/types/user.types.cjs +17 -0
- package/dist/cjs/types/user.types.cjs.map +1 -0
- package/dist/cjs/utils/CSRF.cjs +47 -0
- package/dist/cjs/utils/CSRF.cjs.map +1 -0
- package/dist/cjs/utils/accessControl.cjs +121 -0
- package/dist/cjs/utils/accessControl.cjs.map +1 -0
- package/dist/cjs/utils/cookies.cjs +59 -0
- package/dist/cjs/utils/cookies.cjs.map +1 -0
- package/dist/cjs/utils/errors/ErrorHandler.cjs +103 -0
- package/dist/cjs/utils/errors/ErrorHandler.cjs.map +1 -0
- package/dist/cjs/utils/errors/ErrorsClass.cjs +65 -0
- package/dist/cjs/utils/errors/ErrorsClass.cjs.map +1 -0
- package/dist/cjs/utils/errors/errorCodes.cjs +837 -0
- package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -0
- package/dist/cjs/utils/errors/index.cjs +37 -0
- package/dist/cjs/utils/errors/index.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs +55 -0
- package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getFiltersAndPaginationFromBody.cjs +65 -0
- package/dist/cjs/utils/filtersAndPagination/getFiltersAndPaginationFromBody.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs +55 -0
- package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs +58 -0
- package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs +52 -0
- package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs.map +1 -0
- package/dist/cjs/utils/httpStatusCodes.cjs +93 -0
- package/dist/cjs/utils/httpStatusCodes.cjs.map +1 -0
- package/dist/cjs/utils/mapper/dictionary.cjs +40 -0
- package/dist/cjs/utils/mapper/dictionary.cjs.map +1 -0
- package/dist/cjs/utils/mapper/organization.cjs +39 -0
- package/dist/cjs/utils/mapper/organization.cjs.map +1 -0
- package/dist/cjs/utils/mapper/project.cjs +39 -0
- package/dist/cjs/utils/mapper/project.cjs.map +1 -0
- package/dist/cjs/utils/mapper/user.cjs +39 -0
- package/dist/cjs/utils/mapper/user.cjs.map +1 -0
- package/dist/cjs/utils/mongoDB/connectDB.cjs +53 -0
- package/dist/cjs/utils/mongoDB/connectDB.cjs.map +1 -0
- package/dist/cjs/utils/oAuth2.cjs +50 -0
- package/dist/cjs/utils/oAuth2.cjs.map +1 -0
- package/dist/cjs/utils/responseData.cjs +66 -0
- package/dist/cjs/utils/responseData.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateArray.cjs +57 -0
- package/dist/cjs/utils/validation/validateArray.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateDictionary.cjs +66 -0
- package/dist/cjs/utils/validation/validateDictionary.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateEmail.cjs +37 -0
- package/dist/cjs/utils/validation/validateEmail.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateOrganization.cjs +79 -0
- package/dist/cjs/utils/validation/validateOrganization.cjs.map +1 -0
- package/dist/cjs/utils/validation/validatePhone.cjs +37 -0
- package/dist/cjs/utils/validation/validatePhone.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateProject.cjs +97 -0
- package/dist/cjs/utils/validation/validateProject.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateString.cjs +39 -0
- package/dist/cjs/utils/validation/validateString.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateUser.cjs +73 -0
- package/dist/cjs/utils/validation/validateUser.cjs.map +1 -0
- package/dist/esm/controllers/dictionary.controller.mjs +321 -0
- package/dist/esm/controllers/dictionary.controller.mjs.map +1 -0
- package/dist/esm/controllers/oAuth2.controller.mjs +25 -0
- package/dist/esm/controllers/oAuth2.controller.mjs.map +1 -0
- package/dist/esm/controllers/organization.controller.mjs +317 -0
- package/dist/esm/controllers/organization.controller.mjs.map +1 -0
- package/dist/esm/controllers/project.controller.mjs +263 -0
- package/dist/esm/controllers/project.controller.mjs.map +1 -0
- package/dist/esm/controllers/projectAccessKey.controller.mjs +98 -0
- package/dist/esm/controllers/projectAccessKey.controller.mjs.map +1 -0
- package/dist/esm/controllers/sessionAuth.controller.mjs +570 -0
- package/dist/esm/controllers/sessionAuth.controller.mjs.map +1 -0
- package/dist/esm/controllers/user.controller.mjs +160 -0
- package/dist/esm/controllers/user.controller.mjs.map +1 -0
- package/dist/esm/emails/InviteUserEmail.mjs +285 -0
- package/dist/esm/emails/InviteUserEmail.mjs.map +1 -0
- package/dist/esm/emails/PasswordChangeConfirmation.mjs +134 -0
- package/dist/esm/emails/PasswordChangeConfirmation.mjs.map +1 -0
- package/dist/esm/emails/ResetUserPassword.mjs +197 -0
- package/dist/esm/emails/ResetUserPassword.mjs.map +1 -0
- package/dist/esm/emails/ValidateUserEmail.mjs +218 -0
- package/dist/esm/emails/ValidateUserEmail.mjs.map +1 -0
- package/dist/esm/emails/Welcome.mjs +173 -0
- package/dist/esm/emails/Welcome.mjs.map +1 -0
- package/dist/esm/emails/index.mjs +6 -0
- package/dist/esm/emails/index.mjs.map +1 -0
- package/dist/esm/export.mjs +15 -0
- package/dist/esm/export.mjs.map +1 -0
- package/dist/esm/index.mjs +102 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/logger/index.mjs +29 -0
- package/dist/esm/logger/index.mjs.map +1 -0
- package/dist/esm/middlewares/admin.middleware.mjs +20 -0
- package/dist/esm/middlewares/admin.middleware.mjs.map +1 -0
- package/dist/esm/middlewares/oAuth2.middleware.mjs +57 -0
- package/dist/esm/middlewares/oAuth2.middleware.mjs.map +1 -0
- package/dist/esm/middlewares/request.middleware.mjs +17 -0
- package/dist/esm/middlewares/request.middleware.mjs.map +1 -0
- package/dist/esm/middlewares/sessionAuth.middleware.mjs +96 -0
- package/dist/esm/middlewares/sessionAuth.middleware.mjs.map +1 -0
- package/dist/esm/models/dictionary.model.mjs +10 -0
- package/dist/esm/models/dictionary.model.mjs.map +1 -0
- package/dist/esm/models/oAuth2.model.mjs +7 -0
- package/dist/esm/models/oAuth2.model.mjs.map +1 -0
- package/dist/esm/models/organization.model.mjs +10 -0
- package/dist/esm/models/organization.model.mjs.map +1 -0
- package/dist/esm/models/project.model.mjs +7 -0
- package/dist/esm/models/project.model.mjs.map +1 -0
- package/dist/esm/models/user.model.mjs +7 -0
- package/dist/esm/models/user.model.mjs.map +1 -0
- package/dist/esm/routes/dictionary.routes.mjs +139 -0
- package/dist/esm/routes/dictionary.routes.mjs.map +1 -0
- package/dist/esm/routes/organization.routes.mjs +116 -0
- package/dist/esm/routes/organization.routes.mjs.map +1 -0
- package/dist/esm/routes/project.routes.mjs +162 -0
- package/dist/esm/routes/project.routes.mjs.map +1 -0
- package/dist/esm/routes/sessionAuth.routes.mjs +134 -0
- package/dist/esm/routes/sessionAuth.routes.mjs.map +1 -0
- package/dist/esm/routes/user.routes.mjs +78 -0
- package/dist/esm/routes/user.routes.mjs.map +1 -0
- package/dist/esm/schemas/dictionary.schema.mjs +45 -0
- package/dist/esm/schemas/dictionary.schema.mjs.map +1 -0
- package/dist/esm/schemas/oAuth2.schema.mjs +31 -0
- package/dist/esm/schemas/oAuth2.schema.mjs.map +1 -0
- package/dist/esm/schemas/organization.schema.mjs +40 -0
- package/dist/esm/schemas/organization.schema.mjs.map +1 -0
- package/dist/esm/schemas/project.schema.mjs +59 -0
- package/dist/esm/schemas/project.schema.mjs.map +1 -0
- package/dist/esm/schemas/user.schema.mjs +81 -0
- package/dist/esm/schemas/user.schema.mjs.map +1 -0
- package/dist/esm/services/dictionary.service.mjs +134 -0
- package/dist/esm/services/dictionary.service.mjs.map +1 -0
- package/dist/esm/services/email.service.mjs +114 -0
- package/dist/esm/services/email.service.mjs.map +1 -0
- package/dist/esm/services/oAuth2.service.mjs +150 -0
- package/dist/esm/services/oAuth2.service.mjs.map +1 -0
- package/dist/esm/services/organization.service.mjs +68 -0
- package/dist/esm/services/organization.service.mjs.map +1 -0
- package/dist/esm/services/project.service.mjs +60 -0
- package/dist/esm/services/project.service.mjs.map +1 -0
- package/dist/esm/services/projectAccessKey.service.mjs +113 -0
- package/dist/esm/services/projectAccessKey.service.mjs.map +1 -0
- package/dist/esm/services/sessionAuth.service.mjs +337 -0
- package/dist/esm/services/sessionAuth.service.mjs.map +1 -0
- package/dist/esm/services/user.service.mjs +122 -0
- package/dist/esm/services/user.service.mjs.map +1 -0
- package/dist/esm/types/Routes.mjs +1 -0
- package/dist/esm/types/Routes.mjs.map +1 -0
- package/dist/esm/types/dictionary.types.mjs +1 -0
- package/dist/esm/types/dictionary.types.mjs.map +1 -0
- package/dist/esm/types/organization.types.mjs +1 -0
- package/dist/esm/types/organization.types.mjs.map +1 -0
- package/dist/esm/types/project.types.mjs +1 -0
- package/dist/esm/types/project.types.mjs.map +1 -0
- package/dist/esm/types/session.types.mjs +1 -0
- package/dist/esm/types/session.types.mjs.map +1 -0
- package/dist/esm/types/user.types.mjs +1 -0
- package/dist/esm/types/user.types.mjs.map +1 -0
- package/dist/esm/utils/CSRF.mjs +21 -0
- package/dist/esm/utils/CSRF.mjs.map +1 -0
- package/dist/esm/utils/accessControl.mjs +95 -0
- package/dist/esm/utils/accessControl.mjs.map +1 -0
- package/dist/esm/utils/cookies.mjs +32 -0
- package/dist/esm/utils/cookies.mjs.map +1 -0
- package/dist/esm/utils/errors/ErrorHandler.mjs +79 -0
- package/dist/esm/utils/errors/ErrorHandler.mjs.map +1 -0
- package/dist/esm/utils/errors/ErrorsClass.mjs +40 -0
- package/dist/esm/utils/errors/ErrorsClass.mjs.map +1 -0
- package/dist/esm/utils/errors/errorCodes.mjs +813 -0
- package/dist/esm/utils/errors/errorCodes.mjs.map +1 -0
- package/dist/esm/utils/errors/index.mjs +10 -0
- package/dist/esm/utils/errors/index.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs +33 -0
- package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getFiltersAndPaginationFromBody.mjs +41 -0
- package/dist/esm/utils/filtersAndPagination/getFiltersAndPaginationFromBody.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs +33 -0
- package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs +36 -0
- package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs +30 -0
- package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs.map +1 -0
- package/dist/esm/utils/httpStatusCodes.mjs +69 -0
- package/dist/esm/utils/httpStatusCodes.mjs.map +1 -0
- package/dist/esm/utils/mapper/dictionary.mjs +16 -0
- package/dist/esm/utils/mapper/dictionary.mjs.map +1 -0
- package/dist/esm/utils/mapper/organization.mjs +15 -0
- package/dist/esm/utils/mapper/organization.mjs.map +1 -0
- package/dist/esm/utils/mapper/project.mjs +15 -0
- package/dist/esm/utils/mapper/project.mjs.map +1 -0
- package/dist/esm/utils/mapper/user.mjs +14 -0
- package/dist/esm/utils/mapper/user.mjs.map +1 -0
- package/dist/esm/utils/mongoDB/connectDB.mjs +19 -0
- package/dist/esm/utils/mongoDB/connectDB.mjs.map +1 -0
- package/dist/esm/utils/oAuth2.mjs +29 -0
- package/dist/esm/utils/oAuth2.mjs.map +1 -0
- package/dist/esm/utils/responseData.mjs +41 -0
- package/dist/esm/utils/responseData.mjs.map +1 -0
- package/dist/esm/utils/validation/validateArray.mjs +33 -0
- package/dist/esm/utils/validation/validateArray.mjs.map +1 -0
- package/dist/esm/utils/validation/validateDictionary.mjs +42 -0
- package/dist/esm/utils/validation/validateDictionary.mjs.map +1 -0
- package/dist/esm/utils/validation/validateEmail.mjs +13 -0
- package/dist/esm/utils/validation/validateEmail.mjs.map +1 -0
- package/dist/esm/utils/validation/validateOrganization.mjs +52 -0
- package/dist/esm/utils/validation/validateOrganization.mjs.map +1 -0
- package/dist/esm/utils/validation/validatePhone.mjs +13 -0
- package/dist/esm/utils/validation/validatePhone.mjs.map +1 -0
- package/dist/esm/utils/validation/validateProject.mjs +70 -0
- package/dist/esm/utils/validation/validateProject.mjs.map +1 -0
- package/dist/esm/utils/validation/validateString.mjs +15 -0
- package/dist/esm/utils/validation/validateString.mjs.map +1 -0
- package/dist/esm/utils/validation/validateUser.mjs +47 -0
- package/dist/esm/utils/validation/validateUser.mjs.map +1 -0
- package/dist/types/controllers/dictionary.controller.d.ts +70 -0
- package/dist/types/controllers/dictionary.controller.d.ts.map +1 -0
- package/dist/types/controllers/oAuth2.controller.d.ts +14 -0
- package/dist/types/controllers/oAuth2.controller.d.ts.map +1 -0
- package/dist/types/controllers/organization.controller.d.ts +72 -0
- package/dist/types/controllers/organization.controller.d.ts.map +1 -0
- package/dist/types/controllers/project.controller.d.ts +59 -0
- package/dist/types/controllers/project.controller.d.ts.map +1 -0
- package/dist/types/controllers/projectAccessKey.controller.d.ts +27 -0
- package/dist/types/controllers/projectAccessKey.controller.d.ts.map +1 -0
- package/dist/types/controllers/sessionAuth.controller.d.ts +120 -0
- package/dist/types/controllers/sessionAuth.controller.d.ts.map +1 -0
- package/dist/types/controllers/user.controller.d.ts +56 -0
- package/dist/types/controllers/user.controller.d.ts.map +1 -0
- package/dist/types/emails/InviteUserEmail.d.ts +22 -0
- package/dist/types/emails/InviteUserEmail.d.ts.map +1 -0
- package/dist/types/emails/PasswordChangeConfirmation.d.ts +16 -0
- package/dist/types/emails/PasswordChangeConfirmation.d.ts.map +1 -0
- package/dist/types/emails/ResetUserPassword.d.ts +17 -0
- package/dist/types/emails/ResetUserPassword.d.ts.map +1 -0
- package/dist/types/emails/ValidateUserEmail.d.ts +17 -0
- package/dist/types/emails/ValidateUserEmail.d.ts.map +1 -0
- package/dist/types/emails/Welcome.d.ts +17 -0
- package/dist/types/emails/Welcome.d.ts.map +1 -0
- package/dist/types/emails/index.d.ts +6 -0
- package/dist/types/emails/index.d.ts.map +1 -0
- package/dist/types/export.d.ts +19 -0
- package/dist/types/export.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger/index.d.ts +2 -0
- package/dist/types/logger/index.d.ts.map +1 -0
- package/dist/types/middlewares/admin.middleware.d.ts +10 -0
- package/dist/types/middlewares/admin.middleware.d.ts.map +1 -0
- package/dist/types/middlewares/oAuth2.middleware.d.ts +9 -0
- package/dist/types/middlewares/oAuth2.middleware.d.ts.map +1 -0
- package/dist/types/middlewares/request.middleware.d.ts +4 -0
- package/dist/types/middlewares/request.middleware.d.ts.map +1 -0
- package/dist/types/middlewares/sessionAuth.middleware.d.ts +20 -0
- package/dist/types/middlewares/sessionAuth.middleware.d.ts.map +1 -0
- package/dist/types/models/dictionary.model.d.ts +11 -0
- package/dist/types/models/dictionary.model.d.ts.map +1 -0
- package/dist/types/models/oAuth2.model.d.ts +10 -0
- package/dist/types/models/oAuth2.model.d.ts.map +1 -0
- package/dist/types/models/organization.model.d.ts +12 -0
- package/dist/types/models/organization.model.d.ts.map +1 -0
- package/dist/types/models/project.model.d.ts +12 -0
- package/dist/types/models/project.model.d.ts.map +1 -0
- package/dist/types/models/user.model.d.ts +3 -0
- package/dist/types/models/user.model.d.ts.map +1 -0
- package/dist/types/routes/dictionary.routes.d.ts +42 -0
- package/dist/types/routes/dictionary.routes.d.ts.map +1 -0
- package/dist/types/routes/organization.routes.d.ts +47 -0
- package/dist/types/routes/organization.routes.d.ts.map +1 -0
- package/dist/types/routes/project.routes.d.ts +57 -0
- package/dist/types/routes/project.routes.d.ts.map +1 -0
- package/dist/types/routes/sessionAuth.routes.d.ts +66 -0
- package/dist/types/routes/sessionAuth.routes.d.ts.map +1 -0
- package/dist/types/routes/user.routes.d.ts +42 -0
- package/dist/types/routes/user.routes.d.ts.map +1 -0
- package/dist/types/schemas/dictionary.schema.d.ts +16 -0
- package/dist/types/schemas/dictionary.schema.d.ts.map +1 -0
- package/dist/types/schemas/oAuth2.schema.d.ts +19 -0
- package/dist/types/schemas/oAuth2.schema.d.ts.map +1 -0
- package/dist/types/schemas/organization.schema.d.ts +17 -0
- package/dist/types/schemas/organization.schema.d.ts.map +1 -0
- package/dist/types/schemas/project.schema.d.ts +17 -0
- package/dist/types/schemas/project.schema.d.ts.map +1 -0
- package/dist/types/schemas/user.schema.d.ts +12 -0
- package/dist/types/schemas/user.schema.d.ts.map +1 -0
- package/dist/types/services/dictionary.service.d.ts +70 -0
- package/dist/types/services/dictionary.service.d.ts.map +1 -0
- package/dist/types/services/email.service.d.ts +18 -0
- package/dist/types/services/email.service.d.ts.map +1 -0
- package/dist/types/services/oAuth2.service.d.ts +85 -0
- package/dist/types/services/oAuth2.service.d.ts.map +1 -0
- package/dist/types/services/organization.service.d.ts +43 -0
- package/dist/types/services/organization.service.d.ts.map +1 -0
- package/dist/types/services/project.service.d.ts +43 -0
- package/dist/types/services/project.service.d.ts.map +1 -0
- package/dist/types/services/projectAccessKey.service.d.ts +16 -0
- package/dist/types/services/projectAccessKey.service.d.ts.map +1 -0
- package/dist/types/services/sessionAuth.service.d.ts +148 -0
- package/dist/types/services/sessionAuth.service.d.ts.map +1 -0
- package/dist/types/services/user.service.d.ts +89 -0
- package/dist/types/services/user.service.d.ts.map +1 -0
- package/dist/types/types/Routes.d.ts +7 -0
- package/dist/types/types/Routes.d.ts.map +1 -0
- package/dist/types/types/dictionary.types.d.ts +35 -0
- package/dist/types/types/dictionary.types.d.ts.map +1 -0
- package/dist/types/types/organization.types.d.ts +21 -0
- package/dist/types/types/organization.types.d.ts.map +1 -0
- package/dist/types/types/project.types.d.ts +40 -0
- package/dist/types/types/project.types.d.ts.map +1 -0
- package/dist/types/types/session.types.d.ts +22 -0
- package/dist/types/types/session.types.d.ts.map +1 -0
- package/dist/types/types/user.types.d.ts +28 -0
- package/dist/types/types/user.types.d.ts.map +1 -0
- package/dist/types/utils/CSRF.d.ts +3 -0
- package/dist/types/utils/CSRF.d.ts.map +1 -0
- package/dist/types/utils/accessControl.d.ts +58 -0
- package/dist/types/utils/accessControl.d.ts.map +1 -0
- package/dist/types/utils/cookies.d.ts +12 -0
- package/dist/types/utils/cookies.d.ts.map +1 -0
- package/dist/types/utils/errors/ErrorHandler.d.ts +32 -0
- package/dist/types/utils/errors/ErrorHandler.d.ts.map +1 -0
- package/dist/types/utils/errors/ErrorsClass.d.ts +26 -0
- package/dist/types/utils/errors/ErrorsClass.d.ts.map +1 -0
- package/dist/types/utils/errors/errorCodes.d.ts +811 -0
- package/dist/types/utils/errors/errorCodes.d.ts.map +1 -0
- package/dist/types/utils/errors/index.d.ts +4 -0
- package/dist/types/utils/errors/index.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts +23 -0
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getFiltersAndPaginationFromBody.d.ts +22 -0
- package/dist/types/utils/filtersAndPagination/getFiltersAndPaginationFromBody.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts +31 -0
- package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts +24 -0
- package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts +22 -0
- package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts.map +1 -0
- package/dist/types/utils/httpStatusCodes.d.ts +395 -0
- package/dist/types/utils/httpStatusCodes.d.ts.map +1 -0
- package/dist/types/utils/mapper/dictionary.d.ts +12 -0
- package/dist/types/utils/mapper/dictionary.d.ts.map +1 -0
- package/dist/types/utils/mapper/organization.d.ts +9 -0
- package/dist/types/utils/mapper/organization.d.ts.map +1 -0
- package/dist/types/utils/mapper/project.d.ts +9 -0
- package/dist/types/utils/mapper/project.d.ts.map +1 -0
- package/dist/types/utils/mapper/user.d.ts +14 -0
- package/dist/types/utils/mapper/user.d.ts.map +1 -0
- package/dist/types/utils/mongoDB/connectDB.d.ts +3 -0
- package/dist/types/utils/mongoDB/connectDB.d.ts.map +1 -0
- package/dist/types/utils/oAuth2.d.ts +6 -0
- package/dist/types/utils/oAuth2.d.ts.map +1 -0
- package/dist/types/utils/responseData.d.ts +53 -0
- package/dist/types/utils/responseData.d.ts.map +1 -0
- package/dist/types/utils/validation/validateArray.d.ts +13 -0
- package/dist/types/utils/validation/validateArray.d.ts.map +1 -0
- package/dist/types/utils/validation/validateDictionary.d.ts +12 -0
- package/dist/types/utils/validation/validateDictionary.d.ts.map +1 -0
- package/dist/types/utils/validation/validateEmail.d.ts +10 -0
- package/dist/types/utils/validation/validateEmail.d.ts.map +1 -0
- package/dist/types/utils/validation/validateOrganization.d.ts +15 -0
- package/dist/types/utils/validation/validateOrganization.d.ts.map +1 -0
- package/dist/types/utils/validation/validatePhone.d.ts +10 -0
- package/dist/types/utils/validation/validatePhone.d.ts.map +1 -0
- package/dist/types/utils/validation/validateProject.d.ts +15 -0
- package/dist/types/utils/validation/validateProject.d.ts.map +1 -0
- package/dist/types/utils/validation/validateString.d.ts +10 -0
- package/dist/types/utils/validation/validateString.d.ts.map +1 -0
- package/dist/types/utils/validation/validateUser.d.ts +15 -0
- package/dist/types/utils/validation/validateUser.d.ts.map +1 -0
- package/package.json +115 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/schemas/user.schema.ts"],"sourcesContent":["import {\n NAMES_MAX_LENGTH,\n NAMES_MIN_LENGTH,\n} from '@utils/validation/validateUser';\nimport { Schema } from 'mongoose';\nimport validator from 'validator';\nimport type { User } from '@/types/user.types';\n\nconst SessionSchema = new Schema(\n {\n sessionToken: {\n type: String,\n required: true,\n },\n expires: {\n type: Date,\n required: true,\n },\n },\n { _id: false } // This prevents Mongoose from creating an _id field for the session subdocument\n);\n\nconst ProviderSchema = new Schema(\n {\n provider: {\n type: String,\n required: true,\n },\n providerAccountId: {\n type: String,\n },\n secret: {\n type: String,\n maxlength: 1024,\n minlength: 6,\n },\n emailValidated: {\n type: Boolean,\n },\n passwordHash: {\n type: String,\n },\n },\n { _id: false } // This prevents Mongoose from creating an _id field for the session subdocument\n);\n\nexport const userSchema = new Schema<User>(\n {\n email: {\n type: String,\n required: true,\n unique: true,\n validate: [validator.isEmail, 'Please fill a valid email address'],\n lowercase: true,\n trim: true,\n },\n name: {\n type: String,\n maxlength: NAMES_MAX_LENGTH,\n minlength: NAMES_MIN_LENGTH,\n },\n phone: {\n type: String,\n maxlength: 20,\n },\n session: {\n type: SessionSchema,\n required: false,\n },\n\n provider: {\n type: [ProviderSchema],\n default: undefined,\n required: false,\n },\n },\n {\n timestamps: true,\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAGO;AACP,sBAAuB;AACvB,uBAAsB;AAGtB,MAAM,gBAAgB,IAAI;AAAA,EACxB;AAAA,IACE,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA,EAAE,KAAK,MAAM;AAAA;AACf;AAEA,MAAM,iBAAiB,IAAI;AAAA,EACzB;AAAA,IACE,UAAU;AAAA,MACR,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IACA,mBAAmB;AAAA,MACjB,MAAM;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,gBAAgB;AAAA,MACd,MAAM;AAAA,IACR;AAAA,IACA,cAAc;AAAA,MACZ,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,EAAE,KAAK,MAAM;AAAA;AACf;AAEO,MAAM,aAAa,IAAI;AAAA,EAC5B;AAAA,IACE,OAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,UAAU,CAAC,iBAAAA,QAAU,SAAS,mCAAmC;AAAA,MACjE,WAAW;AAAA,MACX,MAAM;AAAA,IACR;AAAA,IACA,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,WAAW;AAAA,IACb;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IAEA,UAAU;AAAA,MACR,MAAM,CAAC,cAAc;AAAA,MACrB,SAAS;AAAA,MACT,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,EACd;AACF;","names":["validator"]}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var dictionary_service_exports = {};
|
|
20
|
+
__export(dictionary_service_exports, {
|
|
21
|
+
countDictionaries: () => countDictionaries,
|
|
22
|
+
createDictionary: () => createDictionary,
|
|
23
|
+
deleteDictionaryById: () => deleteDictionaryById,
|
|
24
|
+
findDictionaries: () => findDictionaries,
|
|
25
|
+
getDictionariesByKeys: () => getDictionariesByKeys,
|
|
26
|
+
getDictionariesKeys: () => getDictionariesKeys,
|
|
27
|
+
getDictionaryById: () => getDictionaryById,
|
|
28
|
+
getDictionaryByKey: () => getDictionaryByKey,
|
|
29
|
+
getExistingDictionaryKey: () => getExistingDictionaryKey,
|
|
30
|
+
updateDictionaryById: () => updateDictionaryById,
|
|
31
|
+
updateDictionaryByKey: () => updateDictionaryByKey
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(dictionary_service_exports);
|
|
34
|
+
var import_dictionary = require('./../models/dictionary.model.cjs');
|
|
35
|
+
var import_errors = require('./../utils/errors/index.cjs');
|
|
36
|
+
var import_validateDictionary = require('./../utils/validation/validateDictionary.cjs');
|
|
37
|
+
const findDictionaries = async (filters, skip = 0, limit = 100) => await import_dictionary.DictionaryModel.find(filters).skip(skip).limit(limit);
|
|
38
|
+
const getDictionaryById = async (dictionaryId) => {
|
|
39
|
+
const dictionary = await import_dictionary.DictionaryModel.findById(dictionaryId);
|
|
40
|
+
if (!dictionary) {
|
|
41
|
+
throw new import_errors.GenericError("DICTIONARY_NOT_FOUND", { dictionaryId });
|
|
42
|
+
}
|
|
43
|
+
return dictionary;
|
|
44
|
+
};
|
|
45
|
+
const getDictionaryByKey = async (dictionaryKey, projectId) => {
|
|
46
|
+
const dictionary = await import_dictionary.DictionaryModel.findOne({
|
|
47
|
+
key: dictionaryKey,
|
|
48
|
+
projectIds: projectId
|
|
49
|
+
});
|
|
50
|
+
if (!dictionary) {
|
|
51
|
+
throw new import_errors.GenericError("DICTIONARY_NOT_FOUND", {
|
|
52
|
+
dictionaryKey,
|
|
53
|
+
projectId
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return dictionary;
|
|
57
|
+
};
|
|
58
|
+
const getDictionariesByKeys = async (dictionaryKey, projectId) => {
|
|
59
|
+
const dictionaries = await import_dictionary.DictionaryModel.find({
|
|
60
|
+
key: dictionaryKey,
|
|
61
|
+
projectIds: projectId
|
|
62
|
+
});
|
|
63
|
+
return dictionaries;
|
|
64
|
+
};
|
|
65
|
+
const getDictionariesKeys = async (projectId) => {
|
|
66
|
+
const dictionaries = await import_dictionary.DictionaryModel.find({
|
|
67
|
+
projectIds: projectId
|
|
68
|
+
}).select("key");
|
|
69
|
+
return dictionaries.map((dictionary) => dictionary.key);
|
|
70
|
+
};
|
|
71
|
+
const countDictionaries = async (filters) => {
|
|
72
|
+
const result = await import_dictionary.DictionaryModel.countDocuments(filters);
|
|
73
|
+
if (typeof result === "undefined") {
|
|
74
|
+
throw new import_errors.GenericError("DICTIONARY_COUNT_FAILED", { filters });
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
};
|
|
78
|
+
const createDictionary = async (dictionary) => {
|
|
79
|
+
const errors = await (0, import_validateDictionary.validateDictionary)(dictionary);
|
|
80
|
+
if (Object.keys(errors).length > 0) {
|
|
81
|
+
throw new import_errors.GenericError("DICTIONARY_INVALID_FIELDS", {
|
|
82
|
+
errors
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return await import_dictionary.DictionaryModel.create(dictionary);
|
|
86
|
+
};
|
|
87
|
+
const getExistingDictionaryKey = async (dictionariesKeys, projectId) => {
|
|
88
|
+
const existingDictionaries = await import_dictionary.DictionaryModel.find({
|
|
89
|
+
key: { $in: dictionariesKeys },
|
|
90
|
+
projectIds: projectId
|
|
91
|
+
});
|
|
92
|
+
const existingDictionariesKey = [];
|
|
93
|
+
const newDictionariesKey = [];
|
|
94
|
+
for (const key of dictionariesKeys) {
|
|
95
|
+
const isDictionaryExist = existingDictionaries.some(
|
|
96
|
+
(dictionary) => dictionary.key === key
|
|
97
|
+
);
|
|
98
|
+
if (isDictionaryExist) {
|
|
99
|
+
existingDictionariesKey.push(key);
|
|
100
|
+
} else {
|
|
101
|
+
newDictionariesKey.push(key);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { existingDictionariesKey, newDictionariesKey };
|
|
105
|
+
};
|
|
106
|
+
const updateDictionaryById = async (dictionaryId, dictionary) => {
|
|
107
|
+
const updatedKeys = Object.keys(dictionary);
|
|
108
|
+
const errors = (0, import_validateDictionary.validateDictionary)(dictionary, updatedKeys);
|
|
109
|
+
if (Object.keys(errors).length > 0) {
|
|
110
|
+
throw new import_errors.GenericError("DICTIONARY_INVALID_FIELDS", {
|
|
111
|
+
dictionaryId,
|
|
112
|
+
errors
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const existingDictionary = await getDictionaryById(dictionaryId);
|
|
116
|
+
const result = await import_dictionary.DictionaryModel.updateOne(
|
|
117
|
+
{ _id: dictionaryId },
|
|
118
|
+
{ ...dictionary, content: [existingDictionary.content, dictionary.content] }
|
|
119
|
+
);
|
|
120
|
+
if (result.matchedCount === 0) {
|
|
121
|
+
throw new import_errors.GenericError("DICTIONARY_UPDATE_FAILED", { dictionaryId });
|
|
122
|
+
}
|
|
123
|
+
return await getDictionaryById(dictionaryId);
|
|
124
|
+
};
|
|
125
|
+
const updateDictionaryByKey = async (dictionaryKey, dictionary, projectId) => {
|
|
126
|
+
const updatedKeys = Object.keys(dictionary);
|
|
127
|
+
const errors = (0, import_validateDictionary.validateDictionary)(dictionary, updatedKeys);
|
|
128
|
+
if (Object.keys(errors).length > 0) {
|
|
129
|
+
throw new import_errors.GenericError("DICTIONARY_INVALID_FIELDS", {
|
|
130
|
+
dictionaryKey,
|
|
131
|
+
projectId,
|
|
132
|
+
errors
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const existingDictionary = await getDictionaryByKey(dictionaryKey, projectId);
|
|
136
|
+
const result = await import_dictionary.DictionaryModel.updateOne(
|
|
137
|
+
{ key: dictionaryKey, projectIds: projectId },
|
|
138
|
+
{ ...dictionary, content: [existingDictionary.content, dictionary.content] }
|
|
139
|
+
);
|
|
140
|
+
if (result.matchedCount === 0) {
|
|
141
|
+
throw new import_errors.GenericError("DICTIONARY_UPDATE_FAILED", { dictionaryKey });
|
|
142
|
+
}
|
|
143
|
+
return await getDictionaryByKey(dictionaryKey, projectId);
|
|
144
|
+
};
|
|
145
|
+
const deleteDictionaryById = async (dictionaryId) => {
|
|
146
|
+
const dictionary = await import_dictionary.DictionaryModel.findByIdAndDelete(dictionaryId);
|
|
147
|
+
if (!dictionary) {
|
|
148
|
+
throw new import_errors.GenericError("DICTIONARY_NOT_FOUND", { dictionaryId });
|
|
149
|
+
}
|
|
150
|
+
return dictionary;
|
|
151
|
+
};
|
|
152
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
153
|
+
0 && (module.exports = {
|
|
154
|
+
countDictionaries,
|
|
155
|
+
createDictionary,
|
|
156
|
+
deleteDictionaryById,
|
|
157
|
+
findDictionaries,
|
|
158
|
+
getDictionariesByKeys,
|
|
159
|
+
getDictionariesKeys,
|
|
160
|
+
getDictionaryById,
|
|
161
|
+
getDictionaryByKey,
|
|
162
|
+
getExistingDictionaryKey,
|
|
163
|
+
updateDictionaryById,
|
|
164
|
+
updateDictionaryByKey
|
|
165
|
+
});
|
|
166
|
+
//# sourceMappingURL=dictionary.service.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/dictionary.service.ts"],"sourcesContent":["import { DictionaryModel } from '@models/dictionary.model';\nimport { GenericError } from '@utils/errors';\nimport type { DictionaryFilters } from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport {\n type DictionaryFields,\n validateDictionary,\n} from '@utils/validation/validateDictionary';\nimport type { ObjectId } from 'mongoose';\nimport type { Dictionary, DictionaryData } from '@/types/dictionary.types';\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<Dictionary[]> =>\n await DictionaryModel.find(filters).skip(skip).limit(limit);\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 */\nexport const getDictionaryById = async (\n dictionaryId: string | ObjectId\n): Promise<Dictionary> => {\n const dictionary = await DictionaryModel.findById(dictionaryId);\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary;\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryKey - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\nexport const getDictionaryByKey = async (\n dictionaryKey: string,\n projectId: string | ObjectId\n): Promise<Dictionary> => {\n const dictionary = await DictionaryModel.findOne({\n key: dictionaryKey,\n projectIds: projectId,\n });\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', {\n dictionaryKey,\n projectId,\n });\n }\n\n return dictionary;\n};\n\nexport const getDictionariesByKeys = async (\n dictionaryKey: string[],\n projectId: string | ObjectId\n): Promise<Dictionary[]> => {\n const dictionaries = await DictionaryModel.find({\n key: dictionaryKey,\n projectIds: projectId,\n });\n\n return dictionaries;\n};\n\nexport const getDictionariesKeys = async (\n projectId: string | ObjectId\n): Promise<string[]> => {\n const dictionaries = await DictionaryModel.find({\n projectIds: projectId,\n }).select('key');\n\n return dictionaries.map((dictionary) => dictionary.key);\n};\n\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<Dictionary> => {\n const errors = await validateDictionary(dictionary);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n errors,\n });\n }\n\n return await DictionaryModel.create(dictionary);\n};\n\ntype GetExistingDictionaryResult = {\n existingDictionariesKey: string[];\n newDictionariesKey: string[];\n};\n\n/**\n * Gets the existing dictionaries from the provided list of keys.\n * @param dictionariesKeys - List of dictionary keys to check.\n * @param projectId - The ID of the project to check the dictionaries against.\n * @returns The existing dictionaries and the new dictionaries.\n */\nexport const getExistingDictionaryKey = async (\n dictionariesKeys: string[],\n projectId: string | ObjectId\n): Promise<GetExistingDictionaryResult> => {\n // Fetch dictionaries from the database where the key is in the provided list\n const existingDictionaries = await DictionaryModel.find({\n key: { $in: dictionariesKeys },\n projectIds: projectId,\n });\n\n // Map existing dictionaries to a LocalDictionary object\n const existingDictionariesKey: string[] = [];\n const newDictionariesKey: string[] = [];\n\n for (const key of dictionariesKeys) {\n const isDictionaryExist = existingDictionaries.some(\n (dictionary) => dictionary.key === key\n );\n\n if (isDictionaryExist) {\n existingDictionariesKey.push(key);\n } else {\n newDictionariesKey.push(key);\n }\n }\n\n return { existingDictionariesKey, newDictionariesKey };\n};\n\n/**\n * Updates an existing dictionary in the database by its ID.\n * @param dictionaryId - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryById = async (\n dictionaryId: string | ObjectId,\n dictionary: Partial<Dictionary>\n): Promise<Dictionary> => {\n const updatedKeys = Object.keys(dictionary) as DictionaryFields;\n const errors = validateDictionary(dictionary, 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 existingDictionary = await getDictionaryById(dictionaryId);\n\n const result = await DictionaryModel.updateOne(\n { _id: dictionaryId },\n { ...dictionary, content: [existingDictionary.content, dictionary.content] }\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryId });\n }\n\n return await getDictionaryById(dictionaryId);\n};\n\n/**\n * Updates an existing dictionary in the database by its key.\n * @param dictionaryKey - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryByKey = async (\n dictionaryKey: string,\n dictionary: Partial<Dictionary>,\n projectId: string | ObjectId\n): Promise<Dictionary> => {\n const updatedKeys = Object.keys(dictionary) as DictionaryFields;\n const errors = validateDictionary(dictionary, 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 existingDictionary = await getDictionaryByKey(dictionaryKey, projectId);\n\n const result = await DictionaryModel.updateOne(\n { key: dictionaryKey, projectIds: projectId },\n { ...dictionary, content: [existingDictionary.content, dictionary.content] }\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryKey });\n }\n\n return await getDictionaryByKey(dictionaryKey, projectId);\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<Dictionary> => {\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"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAgC;AAChC,oBAA6B;AAE7B,gCAGO;AAWA,MAAM,mBAAmB,OAC9B,SACA,OAAO,GACP,QAAQ,QAER,M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S,GAAG;AAClC,UAAM,IAAI,2BAAa,6BAA6B;AAAA,MAClD;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,qBAAqB,MAAM,mBAAmB,eAAe,SAAS;AAE5E,QAAM,SAAS,MAAM,kCAAgB;AAAA,IACnC,EAAE,KAAK,eAAe,YAAY,UAAU;AAAA,IAC5C,EAAE,GAAG,YAAY,SAAS,CAAC,mBAAmB,SAAS,WAAW,OAAO,EAAE;AAAA,EAC7E;AAEA,MAAI,OAAO,iBAAiB,GAAG;AAC7B,UAAM,IAAI,2BAAa,4BAA4B,EAAE,cAAc,CAAC;AAAA,EACtE;AAEA,SAAO,MAAM,mBAAmB,eAAe,SAAS;AAC1D;AAOO,MAAM,uBAAuB,OAClC,iBACwB;AACxB,QAAM,aAAa,MAAM,kCAAgB,kBAAkB,YAAY;AAEvE,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,2BAAa,wBAAwB,EAAE,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var email_service_exports = {};
|
|
20
|
+
__export(email_service_exports, {
|
|
21
|
+
sendEmail: () => sendEmail
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(email_service_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_InviteUserEmail = require('./../emails/InviteUserEmail.cjs');
|
|
26
|
+
var import_PasswordChangeConfirmation = require('./../emails/PasswordChangeConfirmation.cjs');
|
|
27
|
+
var import_ResetUserPassword = require('./../emails/ResetUserPassword.cjs');
|
|
28
|
+
var import_ValidateUserEmail = require('./../emails/ValidateUserEmail.cjs');
|
|
29
|
+
var import_Welcome = require('./../emails/Welcome.cjs');
|
|
30
|
+
var import_logger = require('./../logger/index.cjs');
|
|
31
|
+
var import_express_intlayer = require("express-intlayer");
|
|
32
|
+
var import_resend = require("resend");
|
|
33
|
+
const getEmailComponents = () => ({
|
|
34
|
+
invite: {
|
|
35
|
+
template: (0, import_express_intlayer.t)({
|
|
36
|
+
en: import_InviteUserEmail.InviteUserEmailEN,
|
|
37
|
+
fr: import_InviteUserEmail.InviteUserEmailFR,
|
|
38
|
+
es: import_InviteUserEmail.InviteUserEmailES
|
|
39
|
+
}),
|
|
40
|
+
subject: (0, import_express_intlayer.t)({
|
|
41
|
+
en: "You have been invited to join Intlayer",
|
|
42
|
+
fr: "Vous \xEAtes invit\xE9 \xE0 rejoindre Intlayer",
|
|
43
|
+
es: "Has sido invitado a unirte a Intlayer"
|
|
44
|
+
})
|
|
45
|
+
},
|
|
46
|
+
validate: {
|
|
47
|
+
template: (0, import_express_intlayer.t)({
|
|
48
|
+
en: import_ValidateUserEmail.ValidateUserEmailEN,
|
|
49
|
+
fr: import_ValidateUserEmail.ValidateUserEmailFR,
|
|
50
|
+
es: import_ValidateUserEmail.ValidateUserEmailES
|
|
51
|
+
}),
|
|
52
|
+
subject: (0, import_express_intlayer.t)({
|
|
53
|
+
en: "Validate your email for Intlayer",
|
|
54
|
+
fr: "Validez votre email pour Intlayer",
|
|
55
|
+
es: "Valida tu correo electr\xF3nico para Intlayer"
|
|
56
|
+
})
|
|
57
|
+
},
|
|
58
|
+
resetPassword: {
|
|
59
|
+
template: (0, import_express_intlayer.t)({
|
|
60
|
+
en: import_ResetUserPassword.ResetPasswordEmailEN,
|
|
61
|
+
fr: import_ResetUserPassword.ResetPasswordEmailFR,
|
|
62
|
+
es: import_ResetUserPassword.ResetPasswordEmailES
|
|
63
|
+
}),
|
|
64
|
+
subject: (0, import_express_intlayer.t)({
|
|
65
|
+
en: "Reset your password for Intlayer",
|
|
66
|
+
fr: "R\xE9initialisez votre mot de passe pour Intlayer",
|
|
67
|
+
es: "Restablece tu contrase\xF1a para Intlayer"
|
|
68
|
+
})
|
|
69
|
+
},
|
|
70
|
+
welcome: {
|
|
71
|
+
template: (0, import_express_intlayer.t)({
|
|
72
|
+
en: import_Welcome.WelcomeEmailEN,
|
|
73
|
+
fr: import_Welcome.WelcomeEmailFR,
|
|
74
|
+
es: import_Welcome.WelcomeEmailES
|
|
75
|
+
}),
|
|
76
|
+
subject: (0, import_express_intlayer.t)({
|
|
77
|
+
en: "Welcome to Intlayer!",
|
|
78
|
+
fr: "Bienvenue chez Intlayer!",
|
|
79
|
+
es: "\xA1Bienvenido a Intlayer!"
|
|
80
|
+
})
|
|
81
|
+
},
|
|
82
|
+
passwordChangeConfirmation: {
|
|
83
|
+
template: (0, import_express_intlayer.t)({
|
|
84
|
+
en: import_PasswordChangeConfirmation.PasswordChangeConfirmationEmailEN,
|
|
85
|
+
fr: import_PasswordChangeConfirmation.PasswordChangeConfirmationEmailFR,
|
|
86
|
+
es: import_PasswordChangeConfirmation.PasswordChangeConfirmationEmailES
|
|
87
|
+
}),
|
|
88
|
+
subject: (0, import_express_intlayer.t)({
|
|
89
|
+
en: "Your Intlayer password has been changed",
|
|
90
|
+
fr: "Votre mot de passe Intlayer a \xE9t\xE9 modifi\xE9",
|
|
91
|
+
es: "Tu contrase\xF1a de Intlayer ha sido cambiada"
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
const sendEmail = async ({
|
|
96
|
+
type,
|
|
97
|
+
to,
|
|
98
|
+
subject,
|
|
99
|
+
...props
|
|
100
|
+
}) => {
|
|
101
|
+
const resend = new import_resend.Resend(process.env.RESEND_API_KEY);
|
|
102
|
+
const emailComponents = getEmailComponents();
|
|
103
|
+
const { template, subject: baseSubject } = emailComponents[type];
|
|
104
|
+
const EmailComponent = template;
|
|
105
|
+
const react = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmailComponent, { ...props });
|
|
106
|
+
await resend.emails.send({
|
|
107
|
+
from: "no-replay@intlayer.org",
|
|
108
|
+
to,
|
|
109
|
+
subject: subject ?? baseSubject,
|
|
110
|
+
react
|
|
111
|
+
}).catch((err) => import_logger.logger.error(err));
|
|
112
|
+
import_logger.logger.info(`Email sent ${type} to ${to}`);
|
|
113
|
+
};
|
|
114
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
115
|
+
0 && (module.exports = {
|
|
116
|
+
sendEmail
|
|
117
|
+
});
|
|
118
|
+
//# sourceMappingURL=email.service.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/email.service.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n InviteUserEmailEN,\n InviteUserEmailFR,\n InviteUserEmailES,\n} from '@emails/InviteUserEmail';\nimport {\n PasswordChangeConfirmationEmailEN,\n PasswordChangeConfirmationEmailFR,\n PasswordChangeConfirmationEmailES,\n} from '@emails/PasswordChangeConfirmation';\nimport {\n ResetPasswordEmailEN,\n ResetPasswordEmailFR,\n ResetPasswordEmailES,\n} from '@emails/ResetUserPassword';\nimport {\n ValidateUserEmailEN,\n ValidateUserEmailFR,\n ValidateUserEmailES,\n} from '@emails/ValidateUserEmail';\nimport {\n WelcomeEmailEN,\n WelcomeEmailFR,\n WelcomeEmailES,\n} from '@emails/Welcome';\nimport { logger } from '@logger';\nimport { t } from 'express-intlayer';\nimport { ComponentProps } from 'react';\nimport { Resend } from 'resend';\n\ntype EmailComponentsType = (...props: any) => JSX.Element;\ntype EmailComponents = {\n [key: string]: {\n template: EmailComponentsType;\n subject: string;\n };\n};\n\nconst getEmailComponents = (): EmailComponents => ({\n invite: {\n template: t<EmailComponentsType>({\n en: InviteUserEmailEN,\n fr: InviteUserEmailFR,\n es: InviteUserEmailES,\n }),\n subject: t({\n en: 'You have been invited to join Intlayer',\n fr: 'Vous êtes invité à rejoindre Intlayer',\n es: 'Has sido invitado a unirte a Intlayer',\n }),\n },\n validate: {\n template: t<EmailComponentsType>({\n en: ValidateUserEmailEN,\n fr: ValidateUserEmailFR,\n es: ValidateUserEmailES,\n }),\n subject: t({\n en: 'Validate your email for Intlayer',\n fr: 'Validez votre email pour Intlayer',\n es: 'Valida tu correo electrónico para Intlayer',\n }),\n },\n resetPassword: {\n template: t<EmailComponentsType>({\n en: ResetPasswordEmailEN,\n fr: ResetPasswordEmailFR,\n es: ResetPasswordEmailES,\n }),\n subject: t({\n en: 'Reset your password for Intlayer',\n fr: 'Réinitialisez votre mot de passe pour Intlayer',\n es: 'Restablece tu contraseña para Intlayer',\n }),\n },\n welcome: {\n template: t<EmailComponentsType>({\n en: WelcomeEmailEN,\n fr: WelcomeEmailFR,\n es: WelcomeEmailES,\n }),\n subject: t({\n en: 'Welcome to Intlayer!',\n fr: 'Bienvenue chez Intlayer!',\n es: '¡Bienvenido a Intlayer!',\n }),\n },\n passwordChangeConfirmation: {\n template: t<EmailComponentsType>({\n en: PasswordChangeConfirmationEmailEN,\n fr: PasswordChangeConfirmationEmailFR,\n es: PasswordChangeConfirmationEmailES,\n }),\n subject: t({\n en: 'Your Intlayer password has been changed',\n fr: 'Votre mot de passe Intlayer a été modifié',\n es: 'Tu contraseña de Intlayer ha sido cambiada',\n }),\n },\n});\n\ntype EmailType = keyof ReturnType<typeof getEmailComponents>;\n\nexport type SendEmailProps<T extends EmailType> = {\n type: T;\n to: string;\n subject?: string;\n} & ComponentProps<ReturnType<typeof getEmailComponents>[T]['template']>;\n\nexport const sendEmail = async <T extends EmailType>({\n type,\n to,\n subject,\n ...props\n}: SendEmailProps<T>) => {\n const resend = new Resend(process.env.RESEND_API_KEY);\n\n const emailComponents = getEmailComponents();\n\n const { template, subject: baseSubject } = emailComponents[type];\n\n type EmailComponentType = (typeof emailComponents)[T]['template'];\n\n const EmailComponent: EmailComponentType = template;\n\n const react = <EmailComponent {...(props as any)} />;\n\n await resend.emails\n .send({\n from: 'no-replay@intlayer.org',\n to,\n subject: subject ?? baseSubject,\n react,\n })\n .catch((err) => logger.error(err));\n\n logger.info(`Email sent ${type} to ${to}`);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8HgB;AA7HhB,6BAIO;AACP,wCAIO;AACP,+BAIO;AACP,+BAIO;AACP,qBAIO;AACP,oBAAuB;AACvB,8BAAkB;AAElB,oBAAuB;AAUvB,MAAM,qBAAqB,OAAwB;AAAA,EACjD,QAAQ;AAAA,IACN,cAAU,2BAAuB;AAAA,MAC/B,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IACN,CAAC;AAAA,IACD,aAAS,2BAAE;AAAA,MACT,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IACN,CAAC;AAAA,EACH;AAAA,EACA,UAAU;AAAA,IACR,cAAU,2BAAuB;AAAA,MAC/B,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IACN,CAAC;AAAA,IACD,aAAS,2BAAE;AAAA,MACT,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IACN,CAAC;AAAA,EACH;AAAA,EACA,eAAe;AAAA,IACb,cAAU,2BAAuB;AAAA,MAC/B,IAAI;AAAA,MAC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ertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var oAuth2_service_exports = {};
|
|
20
|
+
__export(oAuth2_service_exports, {
|
|
21
|
+
formatDBToken: () => formatDBToken,
|
|
22
|
+
formatOAuth2Token: () => formatOAuth2Token,
|
|
23
|
+
generateClientCredentials: () => generateClientCredentials,
|
|
24
|
+
getAccessToken: () => getAccessToken,
|
|
25
|
+
getClient: () => getClient,
|
|
26
|
+
getClientAndProjectByClientId: () => getClientAndProjectByClientId,
|
|
27
|
+
getUserFromClient: () => getUserFromClient,
|
|
28
|
+
saveToken: () => saveToken,
|
|
29
|
+
verifyScope: () => verifyScope
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(oAuth2_service_exports);
|
|
32
|
+
var import_crypto = require("crypto");
|
|
33
|
+
var import_oAuth2 = require('./../models/oAuth2.model.cjs');
|
|
34
|
+
var import_project = require('./../models/project.model.cjs');
|
|
35
|
+
var import_errors = require('./../utils/errors/index.cjs');
|
|
36
|
+
var import_oAuth22 = require('./../utils/oAuth2.cjs');
|
|
37
|
+
var import_organization = require('./organization.service.cjs');
|
|
38
|
+
var import_user = require('./user.service.cjs');
|
|
39
|
+
const generateClientCredentials = () => {
|
|
40
|
+
const clientId = (0, import_crypto.randomBytes)(16).toString("hex");
|
|
41
|
+
const clientSecret = (0, import_crypto.randomBytes)(32).toString("hex");
|
|
42
|
+
return { clientId, clientSecret };
|
|
43
|
+
};
|
|
44
|
+
const getClientAndProjectByClientId = async (clientId) => {
|
|
45
|
+
const project = await import_project.ProjectModel.findOne({
|
|
46
|
+
"oAuth2Access.clientId": clientId
|
|
47
|
+
});
|
|
48
|
+
if (!project) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const oAuth2Access = project.oAuth2Access.find(
|
|
52
|
+
(access) => access.clientId === clientId
|
|
53
|
+
);
|
|
54
|
+
if (!oAuth2Access) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const formattedClient = {
|
|
58
|
+
id: oAuth2Access.clientId,
|
|
59
|
+
clientId,
|
|
60
|
+
clientSecret: oAuth2Access.clientSecret,
|
|
61
|
+
grants: ["client_credentials"]
|
|
62
|
+
};
|
|
63
|
+
return { client: formattedClient, oAuth2Access, project };
|
|
64
|
+
};
|
|
65
|
+
const getClient = async (clientId, clientSecret) => {
|
|
66
|
+
const result = await getClientAndProjectByClientId(clientId);
|
|
67
|
+
if (!result) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const { client } = result;
|
|
71
|
+
if (!client || client.clientSecret !== clientSecret) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return client;
|
|
75
|
+
};
|
|
76
|
+
const formatOAuth2Token = (token, client, user, project, organization) => {
|
|
77
|
+
const { clientId, userId, ...restToken } = token;
|
|
78
|
+
if (String(userId) !== String(user._id)) {
|
|
79
|
+
throw new import_errors.GenericError("USER_ID_MISMATCH");
|
|
80
|
+
}
|
|
81
|
+
const formattedToken = {
|
|
82
|
+
...restToken,
|
|
83
|
+
client,
|
|
84
|
+
user,
|
|
85
|
+
organization,
|
|
86
|
+
project,
|
|
87
|
+
accessToken: token.accessToken,
|
|
88
|
+
accessTokenExpiresAt: token.accessTokenExpiresAt ?? /* @__PURE__ */ new Date("999-99-99")
|
|
89
|
+
};
|
|
90
|
+
return formattedToken;
|
|
91
|
+
};
|
|
92
|
+
const formatDBToken = (token, clientId, userId) => {
|
|
93
|
+
const formattedToken = {
|
|
94
|
+
clientId,
|
|
95
|
+
userId,
|
|
96
|
+
accessToken: token.accessToken,
|
|
97
|
+
expiresIn: token.accessTokenExpiresAt ?? (0, import_oAuth22.getTokenExpireAt)()
|
|
98
|
+
};
|
|
99
|
+
return formattedToken;
|
|
100
|
+
};
|
|
101
|
+
const saveToken = async (token, client, user) => {
|
|
102
|
+
const formattedAccessToken = formatDBToken(token, client.id, user._id);
|
|
103
|
+
const result = await import_oAuth2.OAuth2AccessTokenModel.create(formattedAccessToken);
|
|
104
|
+
if (!result) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
const result2 = await getClientAndProjectByClientId(result.clientId);
|
|
108
|
+
if (!result2) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
const { project } = result2;
|
|
112
|
+
const organization = await (0, import_organization.getOrganizationById)(project.organizationId);
|
|
113
|
+
if (!organization) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const formattedResult = formatOAuth2Token(
|
|
117
|
+
formattedAccessToken,
|
|
118
|
+
client,
|
|
119
|
+
user,
|
|
120
|
+
project,
|
|
121
|
+
organization
|
|
122
|
+
);
|
|
123
|
+
return formattedResult;
|
|
124
|
+
};
|
|
125
|
+
const getAccessToken = async (accessToken) => {
|
|
126
|
+
const token = await import_oAuth2.OAuth2AccessTokenModel.findOne({
|
|
127
|
+
accessToken
|
|
128
|
+
});
|
|
129
|
+
if (!token) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const { userId, clientId } = token;
|
|
133
|
+
const user = await (0, import_user.getUserById)(userId);
|
|
134
|
+
if (!user) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
const result = await getClientAndProjectByClientId(clientId);
|
|
138
|
+
if (!result) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
const { client, project } = result;
|
|
142
|
+
const organization = await (0, import_organization.getOrganizationById)(project.organizationId);
|
|
143
|
+
if (!organization) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
const formattedAccessToken = formatOAuth2Token(
|
|
147
|
+
token,
|
|
148
|
+
client,
|
|
149
|
+
user,
|
|
150
|
+
project,
|
|
151
|
+
organization
|
|
152
|
+
);
|
|
153
|
+
return formattedAccessToken;
|
|
154
|
+
};
|
|
155
|
+
const getUserFromClient = async (client) => {
|
|
156
|
+
const response = await getClientAndProjectByClientId(client.id);
|
|
157
|
+
if (!response) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
const { userId } = response.oAuth2Access;
|
|
161
|
+
if (!userId) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
const user = (0, import_user.getUserById)(userId);
|
|
165
|
+
return user;
|
|
166
|
+
};
|
|
167
|
+
const verifyScope = async (_token, _scope, _callback) => {
|
|
168
|
+
return true;
|
|
169
|
+
};
|
|
170
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
171
|
+
0 && (module.exports = {
|
|
172
|
+
formatDBToken,
|
|
173
|
+
formatOAuth2Token,
|
|
174
|
+
generateClientCredentials,
|
|
175
|
+
getAccessToken,
|
|
176
|
+
getClient,
|
|
177
|
+
getClientAndProjectByClientId,
|
|
178
|
+
getUserFromClient,
|
|
179
|
+
saveToken,
|
|
180
|
+
verifyScope
|
|
181
|
+
});
|
|
182
|
+
//# sourceMappingURL=oAuth2.service.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/oAuth2.service.ts"],"sourcesContent":["import { randomBytes } from 'crypto';\nimport { OAuth2AccessTokenModel } from '@models/oAuth2.model';\nimport { ProjectModel } from '@models/project.model';\nimport { GenericError } from '@utils/errors';\nimport { getTokenExpireAt } from '@utils/oAuth2';\nimport { Client, User, Token as OAuth2Token, Callback } from 'oauth2-server';\nimport { Token } from '../schemas/oAuth2.schema';\nimport { getOrganizationById } from './organization.service';\nimport { getUserById } from './user.service';\nimport { Organization } from '@/types/organization.types';\nimport { OAuth2Access, Project } from '@/types/project.types';\n\n/**\n * Function to generate client credentials\n *\n * @returns The client id and client secret\n */\nexport const generateClientCredentials = (): {\n clientId: string;\n clientSecret: string;\n} => {\n const clientId = randomBytes(16).toString('hex'); // Generate a 16 character hexadecimal string\n const clientSecret = randomBytes(32).toString('hex'); // Generate a 32 character hexadecimal string\n\n return { clientId, clientSecret };\n};\n\n/**\n * Method to get the client and the project\n *\n * @param clientId - The client id\n * @param clientSecret - The client secret\n * @returns The an object containing the client and the project or false if not found\n */\nexport const getClientAndProjectByClientId = async (\n clientId: string\n): Promise<\n { client: Client; oAuth2Access: OAuth2Access; project: Project } | false\n> => {\n const project = await ProjectModel.findOne({\n 'oAuth2Access.clientId': clientId,\n });\n\n if (!project) {\n return false;\n }\n\n const oAuth2Access = project.oAuth2Access.find(\n (access) => access.clientId === clientId\n );\n\n if (!oAuth2Access) {\n return false;\n }\n\n const formattedClient: Client = {\n id: oAuth2Access.clientId,\n clientId,\n clientSecret: oAuth2Access.clientSecret,\n grants: ['client_credentials'],\n };\n\n return { client: formattedClient, oAuth2Access, project };\n};\n\n/**\n * Get the client and verify that the client secret is correct\n *\n * @param clientId - The client id\n * @param clientSecret - The client secret\n * @returns The client or false if not found\n */\nexport const getClient = async (\n clientId: string,\n clientSecret: string\n): Promise<Client | false> => {\n const result = await getClientAndProjectByClientId(clientId);\n\n if (!result) {\n return false;\n }\n\n const { client } = result;\n\n if (!client || client.clientSecret !== clientSecret) {\n return false;\n }\n\n return client;\n};\n\n/**\n * Format an OAuth2Token\n *\n * @param token\n * @param client\n * @param user\n * @param project\n * @param organization\n * @returns\n */\nexport const formatOAuth2Token = (\n token: Token,\n client: Client,\n user: User,\n project: Project,\n organization: Organization\n): OAuth2Token => {\n const { clientId, userId, ...restToken } = token;\n\n if (String(userId) !== String(user._id)) {\n throw new GenericError('USER_ID_MISMATCH');\n }\n\n const formattedToken: OAuth2Token = {\n ...restToken,\n client,\n user,\n organization,\n project,\n accessToken: token.accessToken,\n accessTokenExpiresAt: token.accessTokenExpiresAt ?? new Date('999-99-99'),\n };\n\n return formattedToken;\n};\n\n/**\n * Format a auth token for the database\n *\n * @param token - The oAuth2 token to format\n * @param clientId - The client ID\n * @param userId - The user ID\n * @returns\n */\nexport const formatDBToken = (\n token: OAuth2Token,\n clientId: Client['id'],\n userId: User['_id']\n): Token => {\n const formattedToken: Token = {\n clientId: clientId,\n userId: userId,\n accessToken: token.accessToken,\n expiresIn: token.accessTokenExpiresAt ?? getTokenExpireAt(),\n };\n\n return formattedToken;\n};\n\n/**\n * Method to save the token\n *\n * @param token - The token\n * @param client - The client\n * @param user - The user\n * @returns The saved token or false if not saved\n */\nexport const saveToken = async (\n token: OAuth2Token,\n client: Client,\n user: User\n): Promise<OAuth2Token | false> => {\n const formattedAccessToken: Token = formatDBToken(token, client.id, user._id);\n\n const result = await OAuth2AccessTokenModel.create(formattedAccessToken);\n\n if (!result) {\n return false;\n }\n\n const result2 = await getClientAndProjectByClientId(result.clientId);\n\n if (!result2) {\n return false;\n }\n\n const { project } = result2;\n\n const organization = await getOrganizationById(project.organizationId);\n\n if (!organization) {\n return false;\n }\n\n const formattedResult = formatOAuth2Token(\n formattedAccessToken,\n client,\n user,\n project,\n organization\n );\n return formattedResult;\n};\n\n/**\n * Method to get the access token\n *\n * @param accessToken - The access token\n * @returns The access token or false if not found\n */\nexport const getAccessToken = async (\n accessToken: string\n): Promise<OAuth2Token | false> => {\n const token = await OAuth2AccessTokenModel.findOne({\n accessToken,\n });\n\n if (!token) {\n return false;\n }\n\n const { userId, clientId } = token;\n\n const user = await getUserById(userId);\n\n if (!user) {\n return false;\n }\n\n const result = await getClientAndProjectByClientId(clientId);\n\n if (!result) {\n return false;\n }\n\n const { client, project } = result;\n\n const organization = await getOrganizationById(project.organizationId);\n\n if (!organization) {\n return false;\n }\n\n const formattedAccessToken = formatOAuth2Token(\n token,\n client,\n user,\n project,\n organization\n );\n\n return formattedAccessToken;\n};\n\n/**\n * Method to get the user from the client\n *\n * @param client - The client\n * @returns The user or false if not found\n */\nexport const getUserFromClient = async (\n client: Client\n): Promise<User | false> => {\n const response = await getClientAndProjectByClientId(client.id);\n\n if (!response) {\n return false;\n }\n\n const { userId } = response.oAuth2Access;\n\n if (!userId) {\n return false;\n }\n\n const user: User = getUserById(userId);\n\n return user;\n};\n\n/**\n * Method to verify the permissions (grants)\n *\n * @param token - The token\n * @param scope - The scope\n * @returns True if the token has the required scope, false otherwise\n */\nexport const verifyScope = async (\n _token: OAuth2Token,\n _scope: string,\n _callback?: Callback<boolean> | undefined\n): Promise<boolean> => {\n // Implement the verification of scopes if necessary\n return true;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4B;AAC5B,oBAAuC;AACvC,qBAA6B;AAC7B,oBAA6B;AAC7B,IAAAA,iBAAiC;AAGjC,0BAAoC;AACpC,kBAA4B;AASrB,MAAM,4BAA4B,MAGpC;AACH,QAAM,eAAW,2BAAY,EAAE,EAAE,SAAS,KAAK;AAC/C,QAAM,mBAAe,2BAAY,EAAE,EAAE,SAAS,KAAK;AAEnD,SAAO,EAAE,UAAU,aAAa;AAClC;AASO,MAAM,gCAAgC,OAC3C,aAGG;AACH,QAAM,UAAU,MAAM,4BAAa,QAAQ;AAAA,IACzC,yBAAyB;AAAA,EAC3B,CAAC;AAED,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,eAAe,QAAQ,aAAa;AAAA,IACxC,CAAC,WAAW,OAAO,aAAa;AAAA,EAClC;AAEA,MAAI,CAAC,cAAc;AACjB,WAAO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0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var organization_service_exports = {};
|
|
20
|
+
__export(organization_service_exports, {
|
|
21
|
+
countOrganizations: () => countOrganizations,
|
|
22
|
+
createOrganization: () => createOrganization,
|
|
23
|
+
deleteOrganizationById: () => deleteOrganizationById,
|
|
24
|
+
findOrganizations: () => findOrganizations,
|
|
25
|
+
getOrganizationById: () => getOrganizationById,
|
|
26
|
+
updateOrganizationById: () => updateOrganizationById
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(organization_service_exports);
|
|
29
|
+
var import_organization = require('./../models/organization.model.cjs');
|
|
30
|
+
var import_errors = require('./../utils/errors/index.cjs');
|
|
31
|
+
var import_validateOrganization = require('./../utils/validation/validateOrganization.cjs');
|
|
32
|
+
const findOrganizations = async (filters, skip, limit) => {
|
|
33
|
+
return await import_organization.OrganizationModel.find(filters).skip(skip).limit(limit);
|
|
34
|
+
};
|
|
35
|
+
const getOrganizationById = async (organizationId) => {
|
|
36
|
+
const organization = await import_organization.OrganizationModel.findById(organizationId);
|
|
37
|
+
if (!organization) {
|
|
38
|
+
throw new import_errors.GenericError("ORGANIZATION_NOT_FOUND", { organizationId });
|
|
39
|
+
}
|
|
40
|
+
return organization;
|
|
41
|
+
};
|
|
42
|
+
const countOrganizations = async (filters) => {
|
|
43
|
+
const result = await import_organization.OrganizationModel.countDocuments(filters);
|
|
44
|
+
if (typeof result === "undefined") {
|
|
45
|
+
throw new import_errors.GenericError("ORGANIZATION_COUNT_FAILED", { filters });
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
const createOrganization = async (organization, userId) => {
|
|
50
|
+
const errors = (0, import_validateOrganization.validateOrganization)(organization, ["name"]);
|
|
51
|
+
if (Object.keys(errors).length > 0) {
|
|
52
|
+
throw new import_errors.GenericError("ORGANIZATION_INVALID_FIELDS", { errors });
|
|
53
|
+
}
|
|
54
|
+
return await import_organization.OrganizationModel.create({
|
|
55
|
+
creatorId: userId,
|
|
56
|
+
membersIds: [userId],
|
|
57
|
+
adminsIds: [userId],
|
|
58
|
+
...organization
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const updateOrganizationById = async (organizationId, organization) => {
|
|
62
|
+
const updatedKeys = Object.keys(organization);
|
|
63
|
+
const errors = (0, import_validateOrganization.validateOrganization)(organization, updatedKeys);
|
|
64
|
+
if (Object.keys(errors).length > 0) {
|
|
65
|
+
throw new import_errors.GenericError("ORGANIZATION_INVALID_FIELDS", {
|
|
66
|
+
organizationId,
|
|
67
|
+
errors
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const result = await import_organization.OrganizationModel.updateOne(
|
|
71
|
+
{ _id: organizationId },
|
|
72
|
+
organization
|
|
73
|
+
);
|
|
74
|
+
if (result.matchedCount === 0) {
|
|
75
|
+
throw new import_errors.GenericError("ORGANIZATION_UPDATE_FAILED", { organizationId });
|
|
76
|
+
}
|
|
77
|
+
return await getOrganizationById(organizationId);
|
|
78
|
+
};
|
|
79
|
+
const deleteOrganizationById = async (organizationId) => {
|
|
80
|
+
const organization = await import_organization.OrganizationModel.findByIdAndDelete(organizationId);
|
|
81
|
+
if (!organization) {
|
|
82
|
+
throw new import_errors.GenericError("ORGANIZATION_NOT_FOUND", { organizationId });
|
|
83
|
+
}
|
|
84
|
+
return organization;
|
|
85
|
+
};
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
countOrganizations,
|
|
89
|
+
createOrganization,
|
|
90
|
+
deleteOrganizationById,
|
|
91
|
+
findOrganizations,
|
|
92
|
+
getOrganizationById,
|
|
93
|
+
updateOrganizationById
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=organization.service.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/organization.service.ts"],"sourcesContent":["import { OrganizationModel } from '@models/organization.model';\nimport { GenericError } from '@utils/errors';\nimport type { OrganizationFilters } from '@utils/filtersAndPagination/getOrganizationFiltersAndPagination';\nimport {\n type OrganizationFields,\n validateOrganization,\n} from '@utils/validation/validateOrganization';\nimport type { ObjectId } from 'mongoose';\nimport type {\n Organization,\n OrganizationCreationData,\n} from '@/types/organization.types';\n\n/**\n * Finds organizations based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of organizations matching the filters.\n */\nexport const findOrganizations = async (\n filters: OrganizationFilters,\n skip: number,\n limit: number\n): Promise<Organization[]> => {\n return await OrganizationModel.find(filters).skip(skip).limit(limit);\n};\n\n/**\n * Finds an organization by its ID.\n * @param organizationId - The ID of the organization to find.\n * @returns The organization matching the ID.\n */\nexport const getOrganizationById = async (\n organizationId: ObjectId | string\n): Promise<Organization> => {\n const organization = await OrganizationModel.findById(organizationId);\n\n if (!organization) {\n throw new GenericError('ORGANIZATION_NOT_FOUND', { organizationId });\n }\n\n return organization;\n};\n\n/**\n * Counts the total number of organizations that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of organizations.\n */\nexport const countOrganizations = async (\n filters: OrganizationFilters\n): Promise<number> => {\n const result = await OrganizationModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('ORGANIZATION_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new organization in the database.\n * @param organization - The organization data to create.\n * @returns The created organization.\n */\nexport const createOrganization = async (\n organization: OrganizationCreationData,\n userId: string | ObjectId\n): Promise<Organization> => {\n const errors = validateOrganization(organization, ['name']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('ORGANIZATION_INVALID_FIELDS', { errors });\n }\n\n return await OrganizationModel.create({\n creatorId: userId,\n membersIds: [userId],\n adminsIds: [userId],\n ...organization,\n });\n};\n\n/**\n * Updates an existing organization in the database by its ID.\n * @param organizationId - The ID of the organization to update.\n * @param organization - The updated organization data.\n * @returns The updated organization.\n */\nexport const updateOrganizationById = async (\n organizationId: ObjectId | string,\n organization: Partial<Organization>\n): Promise<Organization> => {\n const updatedKeys = Object.keys(organization) as OrganizationFields;\n const errors = validateOrganization(organization, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('ORGANIZATION_INVALID_FIELDS', {\n organizationId,\n errors,\n });\n }\n\n const result = await OrganizationModel.updateOne(\n { _id: organizationId },\n organization\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('ORGANIZATION_UPDATE_FAILED', { organizationId });\n }\n\n return await getOrganizationById(organizationId);\n};\n\n/**\n * Deletes an organization from the database by its ID.\n * @param organizationId - The ID of the organization to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteOrganizationById = async (\n organizationId: ObjectId | string\n): Promise<Organization> => {\n const organization =\n await OrganizationModel.findByIdAndDelete(organizationId);\n\n if (!organization) {\n throw new GenericError('ORGANIZATION_NOT_FOUND', { organizationId });\n }\n\n return organization;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;A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