@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,150 @@
|
|
|
1
|
+
import { randomBytes } from "crypto";
|
|
2
|
+
import { OAuth2AccessTokenModel } from './../models/oAuth2.model.mjs';
|
|
3
|
+
import { ProjectModel } from './../models/project.model.mjs';
|
|
4
|
+
import { GenericError } from './../utils/errors/index.mjs';
|
|
5
|
+
import { getTokenExpireAt } from './../utils/oAuth2.mjs';
|
|
6
|
+
import { getOrganizationById } from './organization.service.mjs';
|
|
7
|
+
import { getUserById } from './user.service.mjs';
|
|
8
|
+
const generateClientCredentials = () => {
|
|
9
|
+
const clientId = randomBytes(16).toString("hex");
|
|
10
|
+
const clientSecret = randomBytes(32).toString("hex");
|
|
11
|
+
return { clientId, clientSecret };
|
|
12
|
+
};
|
|
13
|
+
const getClientAndProjectByClientId = async (clientId) => {
|
|
14
|
+
const project = await ProjectModel.findOne({
|
|
15
|
+
"oAuth2Access.clientId": clientId
|
|
16
|
+
});
|
|
17
|
+
if (!project) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const oAuth2Access = project.oAuth2Access.find(
|
|
21
|
+
(access) => access.clientId === clientId
|
|
22
|
+
);
|
|
23
|
+
if (!oAuth2Access) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const formattedClient = {
|
|
27
|
+
id: oAuth2Access.clientId,
|
|
28
|
+
clientId,
|
|
29
|
+
clientSecret: oAuth2Access.clientSecret,
|
|
30
|
+
grants: ["client_credentials"]
|
|
31
|
+
};
|
|
32
|
+
return { client: formattedClient, oAuth2Access, project };
|
|
33
|
+
};
|
|
34
|
+
const getClient = async (clientId, clientSecret) => {
|
|
35
|
+
const result = await getClientAndProjectByClientId(clientId);
|
|
36
|
+
if (!result) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const { client } = result;
|
|
40
|
+
if (!client || client.clientSecret !== clientSecret) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return client;
|
|
44
|
+
};
|
|
45
|
+
const formatOAuth2Token = (token, client, user, project, organization) => {
|
|
46
|
+
const { clientId, userId, ...restToken } = token;
|
|
47
|
+
if (String(userId) !== String(user._id)) {
|
|
48
|
+
throw new GenericError("USER_ID_MISMATCH");
|
|
49
|
+
}
|
|
50
|
+
const formattedToken = {
|
|
51
|
+
...restToken,
|
|
52
|
+
client,
|
|
53
|
+
user,
|
|
54
|
+
organization,
|
|
55
|
+
project,
|
|
56
|
+
accessToken: token.accessToken,
|
|
57
|
+
accessTokenExpiresAt: token.accessTokenExpiresAt ?? /* @__PURE__ */ new Date("999-99-99")
|
|
58
|
+
};
|
|
59
|
+
return formattedToken;
|
|
60
|
+
};
|
|
61
|
+
const formatDBToken = (token, clientId, userId) => {
|
|
62
|
+
const formattedToken = {
|
|
63
|
+
clientId,
|
|
64
|
+
userId,
|
|
65
|
+
accessToken: token.accessToken,
|
|
66
|
+
expiresIn: token.accessTokenExpiresAt ?? getTokenExpireAt()
|
|
67
|
+
};
|
|
68
|
+
return formattedToken;
|
|
69
|
+
};
|
|
70
|
+
const saveToken = async (token, client, user) => {
|
|
71
|
+
const formattedAccessToken = formatDBToken(token, client.id, user._id);
|
|
72
|
+
const result = await OAuth2AccessTokenModel.create(formattedAccessToken);
|
|
73
|
+
if (!result) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const result2 = await getClientAndProjectByClientId(result.clientId);
|
|
77
|
+
if (!result2) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const { project } = result2;
|
|
81
|
+
const organization = await getOrganizationById(project.organizationId);
|
|
82
|
+
if (!organization) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const formattedResult = formatOAuth2Token(
|
|
86
|
+
formattedAccessToken,
|
|
87
|
+
client,
|
|
88
|
+
user,
|
|
89
|
+
project,
|
|
90
|
+
organization
|
|
91
|
+
);
|
|
92
|
+
return formattedResult;
|
|
93
|
+
};
|
|
94
|
+
const getAccessToken = async (accessToken) => {
|
|
95
|
+
const token = await OAuth2AccessTokenModel.findOne({
|
|
96
|
+
accessToken
|
|
97
|
+
});
|
|
98
|
+
if (!token) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
const { userId, clientId } = token;
|
|
102
|
+
const user = await getUserById(userId);
|
|
103
|
+
if (!user) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
const result = await getClientAndProjectByClientId(clientId);
|
|
107
|
+
if (!result) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
const { client, project } = result;
|
|
111
|
+
const organization = await getOrganizationById(project.organizationId);
|
|
112
|
+
if (!organization) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
const formattedAccessToken = formatOAuth2Token(
|
|
116
|
+
token,
|
|
117
|
+
client,
|
|
118
|
+
user,
|
|
119
|
+
project,
|
|
120
|
+
organization
|
|
121
|
+
);
|
|
122
|
+
return formattedAccessToken;
|
|
123
|
+
};
|
|
124
|
+
const getUserFromClient = async (client) => {
|
|
125
|
+
const response = await getClientAndProjectByClientId(client.id);
|
|
126
|
+
if (!response) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
const { userId } = response.oAuth2Access;
|
|
130
|
+
if (!userId) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
const user = getUserById(userId);
|
|
134
|
+
return user;
|
|
135
|
+
};
|
|
136
|
+
const verifyScope = async (_token, _scope, _callback) => {
|
|
137
|
+
return true;
|
|
138
|
+
};
|
|
139
|
+
export {
|
|
140
|
+
formatDBToken,
|
|
141
|
+
formatOAuth2Token,
|
|
142
|
+
generateClientCredentials,
|
|
143
|
+
getAccessToken,
|
|
144
|
+
getClient,
|
|
145
|
+
getClientAndProjectByClientId,
|
|
146
|
+
getUserFromClient,
|
|
147
|
+
saveToken,
|
|
148
|
+
verifyScope
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=oAuth2.service.mjs.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,SAAS,mBAAmB;AAC5B,SAAS,8BAA8B;AACvC,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AAGjC,SAAS,2BAA2B;AACpC,SAAS,mBAAmB;AASrB,MAAM,4BAA4B,MAGpC;AACH,QAAM,WAAW,YAAY,EAAE,EAAE,SAAS,KAAK;AAC/C,QAAM,eAAe,YAAY,EAAE,EAAE,SAAS,KAAK;AAEnD,SAAO,EAAE,UAAU,aAAa;AAClC;AASO,MAAM,gCAAgC,OAC3C,aAGG;AACH,QAAM,UAAU,MAAM,aAAa,QAAQ;AAAA,IACzC,yBAAyB;AAAA,EAC3B,CAAC;AAED,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,eAAe,QAAQ,aAAa;AAAA,IACxC,CAAC,WAAW,OAAO,aAAa;AAAA,EAClC;AAEA,MAAI,CAAC,cAAc;AACjB,WAAO;AAAA,EACT;AAEA,QAAM,kBAA0B;AAAA,IAC9B,IAAI,aAAa;AAAA,IACjB;AAAA,IACA,cAAc,aAAa;AAAA,IAC3B,QAAQ,CAAC,oBAAoB;AAAA,EAC/B;AAEA,SAAO,EAAE,QAAQ,iBAAiB,cAAc,QAAQ;AAC1D;AASO,MAAM,YAAY,OACvB,UACA,iBAC4B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;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO;AACT;AAQO,MAAM,iBAAiB,OAC5B,gBACiC;AACjC,QAAM,QAAQ,MAAM,uBAAuB,QAAQ;AAAA,IACjD;AAAA,EACF,CAAC;AAED,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,QAAQ,SAAS,IAAI;AAE7B,QAAM,OAAO,MAAM,YAAY,MAAM;AAErC,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,MAAM,8BAA8B,QAAQ;AAE3D,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,QAAM,eAAe,MAAM,oBAAoB,QAAQ,cAAc;AAErE,MAAI,CAAC,cAAc;AACjB,WAAO;AAAA,EACT;AAEA,QAAM,uBAAuB;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;AAQO,MAAM,oBAAoB,OAC/B,WAC0B;AAC1B,QAAM,WAAW,MAAM,8BAA8B,OAAO,EAAE;AAE9D,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,OAAO,IAAI,SAAS;AAE5B,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,QAAM,OAAa,YAAY,MAAM;AAErC,SAAO;AACT;AASO,MAAM,cAAc,OACzB,QACA,QACA,cACqB;AAErB,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { OrganizationModel } from './../models/organization.model.mjs';
|
|
2
|
+
import { GenericError } from './../utils/errors/index.mjs';
|
|
3
|
+
import {
|
|
4
|
+
validateOrganization
|
|
5
|
+
} from './../utils/validation/validateOrganization.mjs';
|
|
6
|
+
const findOrganizations = async (filters, skip, limit) => {
|
|
7
|
+
return await OrganizationModel.find(filters).skip(skip).limit(limit);
|
|
8
|
+
};
|
|
9
|
+
const getOrganizationById = async (organizationId) => {
|
|
10
|
+
const organization = await OrganizationModel.findById(organizationId);
|
|
11
|
+
if (!organization) {
|
|
12
|
+
throw new GenericError("ORGANIZATION_NOT_FOUND", { organizationId });
|
|
13
|
+
}
|
|
14
|
+
return organization;
|
|
15
|
+
};
|
|
16
|
+
const countOrganizations = async (filters) => {
|
|
17
|
+
const result = await OrganizationModel.countDocuments(filters);
|
|
18
|
+
if (typeof result === "undefined") {
|
|
19
|
+
throw new GenericError("ORGANIZATION_COUNT_FAILED", { filters });
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
const createOrganization = async (organization, userId) => {
|
|
24
|
+
const errors = validateOrganization(organization, ["name"]);
|
|
25
|
+
if (Object.keys(errors).length > 0) {
|
|
26
|
+
throw new GenericError("ORGANIZATION_INVALID_FIELDS", { errors });
|
|
27
|
+
}
|
|
28
|
+
return await OrganizationModel.create({
|
|
29
|
+
creatorId: userId,
|
|
30
|
+
membersIds: [userId],
|
|
31
|
+
adminsIds: [userId],
|
|
32
|
+
...organization
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const updateOrganizationById = async (organizationId, organization) => {
|
|
36
|
+
const updatedKeys = Object.keys(organization);
|
|
37
|
+
const errors = validateOrganization(organization, updatedKeys);
|
|
38
|
+
if (Object.keys(errors).length > 0) {
|
|
39
|
+
throw new GenericError("ORGANIZATION_INVALID_FIELDS", {
|
|
40
|
+
organizationId,
|
|
41
|
+
errors
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const result = await OrganizationModel.updateOne(
|
|
45
|
+
{ _id: organizationId },
|
|
46
|
+
organization
|
|
47
|
+
);
|
|
48
|
+
if (result.matchedCount === 0) {
|
|
49
|
+
throw new GenericError("ORGANIZATION_UPDATE_FAILED", { organizationId });
|
|
50
|
+
}
|
|
51
|
+
return await getOrganizationById(organizationId);
|
|
52
|
+
};
|
|
53
|
+
const deleteOrganizationById = async (organizationId) => {
|
|
54
|
+
const organization = await OrganizationModel.findByIdAndDelete(organizationId);
|
|
55
|
+
if (!organization) {
|
|
56
|
+
throw new GenericError("ORGANIZATION_NOT_FOUND", { organizationId });
|
|
57
|
+
}
|
|
58
|
+
return organization;
|
|
59
|
+
};
|
|
60
|
+
export {
|
|
61
|
+
countOrganizations,
|
|
62
|
+
createOrganization,
|
|
63
|
+
deleteOrganizationById,
|
|
64
|
+
findOrganizations,
|
|
65
|
+
getOrganizationById,
|
|
66
|
+
updateOrganizationById
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=organization.service.mjs.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,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAE7B;AAAA,EAEE;AAAA,OACK;AAcA,MAAM,oBAAoB,OAC/B,SACA,MACA,U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;AAAA,EACzE;AAEA,SAAO,MAAM,oBAAoB,cAAc;AACjD;AAOO,MAAM,yBAAyB,OACpC,mBAC0B;AAC1B,QAAM,eACJ,MAAM,kBAAkB,kBAAkB,cAAc;AAE1D,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI,aAAa,0BAA0B,EAAE,eAAe,CAAC;AAAA,EACrE;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ProjectModel } from './../models/project.model.mjs';
|
|
2
|
+
import { GenericError } from './../utils/errors/index.mjs';
|
|
3
|
+
import {
|
|
4
|
+
validateProject
|
|
5
|
+
} from './../utils/validation/validateProject.mjs';
|
|
6
|
+
const findProjects = async (filters, skip = 0, limit = 100) => {
|
|
7
|
+
return await ProjectModel.find(filters).skip(skip).limit(limit);
|
|
8
|
+
};
|
|
9
|
+
const getProjectById = async (projectId) => {
|
|
10
|
+
const project = await ProjectModel.findById(projectId);
|
|
11
|
+
if (!project) {
|
|
12
|
+
throw new GenericError("PROJECT_NOT_FOUND", { projectId });
|
|
13
|
+
}
|
|
14
|
+
return project;
|
|
15
|
+
};
|
|
16
|
+
const countProjects = async (filters) => {
|
|
17
|
+
const result = await ProjectModel.countDocuments(filters);
|
|
18
|
+
if (typeof result === "undefined") {
|
|
19
|
+
throw new GenericError("PROJECT_COUNT_FAILED", { filters });
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
const createProject = async (project) => {
|
|
24
|
+
const errors = await validateProject(project, ["name"]);
|
|
25
|
+
if (Object.keys(errors).length > 0) {
|
|
26
|
+
throw new GenericError("PROJECT_INVALID_FIELDS", { errors });
|
|
27
|
+
}
|
|
28
|
+
return await ProjectModel.create(project);
|
|
29
|
+
};
|
|
30
|
+
const updateProjectById = async (projectId, project) => {
|
|
31
|
+
const updatedKeys = Object.keys(project);
|
|
32
|
+
const errors = validateProject(project, updatedKeys);
|
|
33
|
+
if (Object.keys(errors).length > 0) {
|
|
34
|
+
throw new GenericError("PROJECT_INVALID_FIELDS", {
|
|
35
|
+
projectId,
|
|
36
|
+
errors
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const result = await ProjectModel.updateOne({ _id: projectId }, project);
|
|
40
|
+
if (result.matchedCount === 0) {
|
|
41
|
+
throw new GenericError("PROJECT_UPDATE_FAILED", { projectId });
|
|
42
|
+
}
|
|
43
|
+
return await getProjectById(projectId);
|
|
44
|
+
};
|
|
45
|
+
const deleteProjectById = async (projectId) => {
|
|
46
|
+
const project = await ProjectModel.findByIdAndDelete(projectId);
|
|
47
|
+
if (!project) {
|
|
48
|
+
throw new GenericError("PROJECT_NOT_FOUND", { projectId });
|
|
49
|
+
}
|
|
50
|
+
return project;
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
countProjects,
|
|
54
|
+
createProject,
|
|
55
|
+
deleteProjectById,
|
|
56
|
+
findProjects,
|
|
57
|
+
getProjectById,
|
|
58
|
+
updateProjectById
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=project.service.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/project.service.ts"],"sourcesContent":["import { ProjectModel } from '@models/project.model';\nimport { GenericError } from '@utils/errors';\nimport type { ProjectFilters } from '@utils/filtersAndPagination/getProjectFiltersAndPagination';\nimport {\n type ProjectFields,\n validateProject,\n} from '@utils/validation/validateProject';\nimport type { ObjectId } from 'mongoose';\nimport type { Project, ProjectData } from '@/types/project.types';\n\n/**\n * Finds projects based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of projects matching the filters.\n */\nexport const findProjects = async (\n filters: ProjectFilters,\n skip = 0,\n limit = 100\n): Promise<Project[]> => {\n return await ProjectModel.find(filters).skip(skip).limit(limit);\n};\n\n/**\n * Finds a project by its ID.\n * @param projectId - The ID of the project to find.\n * @returns The project matching the ID.\n */\nexport const getProjectById = async (\n projectId: string | ObjectId\n): Promise<Project> => {\n const project = await ProjectModel.findById(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_FOUND', { 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 (project: ProjectData): Promise<Project> => {\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 | ObjectId,\n project: Partial<Project>\n): Promise<Project> => {\n const updatedKeys = Object.keys(project) as ProjectFields;\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({ _id: projectId }, project);\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 | ObjectId\n): Promise<Project> => {\n const project = await ProjectModel.findByIdAndDelete(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_FOUND', { projectId });\n }\n\n return project;\n};\n"],"mappings":"AAAA,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAE7B;AAAA,EAEE;AAAA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B;AACrB,QAAM,UAAU,MAAM,aAAa,kBAAkB,SAAS;AAE9D,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,aAAa,qBAAqB,EAAE,UAAU,CAAC;AAAA,EAC3D;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { ProjectModel } from './../models/project.model.mjs';
|
|
2
|
+
import { GenericError } from './../utils/errors/index.mjs';
|
|
3
|
+
import { generateClientCredentials } from './oAuth2.service.mjs';
|
|
4
|
+
import { getProjectById } from './project.service.mjs';
|
|
5
|
+
const addNewAccessKey = async (accessKeyData, projectId, user) => {
|
|
6
|
+
const { clientId, clientSecret } = generateClientCredentials();
|
|
7
|
+
const newAccessKey = {
|
|
8
|
+
...accessKeyData,
|
|
9
|
+
clientId,
|
|
10
|
+
clientSecret,
|
|
11
|
+
userId: user._id,
|
|
12
|
+
accessToken: []
|
|
13
|
+
};
|
|
14
|
+
const result = await ProjectModel.updateOne(
|
|
15
|
+
{ _id: projectId },
|
|
16
|
+
{ $push: { oAuth2Access: newAccessKey } }
|
|
17
|
+
);
|
|
18
|
+
if (result.modifiedCount === 0) {
|
|
19
|
+
throw new GenericError("ACCESS_KEY_CREATION_FAILED", {
|
|
20
|
+
accessKeyData,
|
|
21
|
+
projectId,
|
|
22
|
+
userId: user._id
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const updatedProject = await getProjectById(projectId);
|
|
26
|
+
const newAccessKeyId = updatedProject.oAuth2Access.find(
|
|
27
|
+
(access) => access.clientId === clientId
|
|
28
|
+
);
|
|
29
|
+
if (!newAccessKeyId) {
|
|
30
|
+
throw new GenericError("ACCESS_KEY_CREATION_FAILED", {
|
|
31
|
+
accessKeyData,
|
|
32
|
+
projectId,
|
|
33
|
+
userId: user._id
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return newAccessKeyId;
|
|
37
|
+
};
|
|
38
|
+
const deleteAccessKey = async (clientId, project) => {
|
|
39
|
+
const projectAccess = project.oAuth2Access.find(
|
|
40
|
+
(access) => access.clientId === clientId
|
|
41
|
+
);
|
|
42
|
+
if (!projectAccess) {
|
|
43
|
+
throw new GenericError("ACCESS_KEY_NOT_FOUND", {
|
|
44
|
+
clientId,
|
|
45
|
+
projectId: project._id
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const result = await ProjectModel.updateOne(
|
|
49
|
+
{ "oAuth2Access.clientId": clientId },
|
|
50
|
+
{ $pull: { oAuth2Access: { clientId } } }
|
|
51
|
+
);
|
|
52
|
+
if (result.modifiedCount === 0) {
|
|
53
|
+
throw new GenericError("ACCESS_KEY_DELETION_FAILED", {
|
|
54
|
+
clientId,
|
|
55
|
+
projectId: project._id
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return projectAccess;
|
|
59
|
+
};
|
|
60
|
+
const refreshAccessKey = async (clientId, projectId) => {
|
|
61
|
+
const project = await ProjectModel.findOne({
|
|
62
|
+
_id: projectId,
|
|
63
|
+
"oAuth2Access.clientId": clientId
|
|
64
|
+
});
|
|
65
|
+
if (!project) {
|
|
66
|
+
throw new GenericError("PROJECT_NOT_FOUND", {
|
|
67
|
+
clientId,
|
|
68
|
+
projectId
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const projectAccess = project.oAuth2Access.find(
|
|
72
|
+
(access) => access.clientId === clientId
|
|
73
|
+
);
|
|
74
|
+
if (!projectAccess) {
|
|
75
|
+
throw new GenericError("ACCESS_KEY_NOT_FOUND", {
|
|
76
|
+
clientId,
|
|
77
|
+
projectId: project._id
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const { clientSecret } = generateClientCredentials();
|
|
81
|
+
const result = await ProjectModel.updateOne(
|
|
82
|
+
{ "oAuth2Access.clientId": clientId },
|
|
83
|
+
{
|
|
84
|
+
$set: {
|
|
85
|
+
"oAuth2Access.$.clientId": projectAccess.clientId,
|
|
86
|
+
"oAuth2Access.$.clientSecret": clientSecret
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
if (result.modifiedCount === 0) {
|
|
91
|
+
throw new GenericError("ACCESS_KEy_UPDATE_FAILED", {
|
|
92
|
+
clientId,
|
|
93
|
+
projectId
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const updatedProject = await getProjectById(projectId);
|
|
97
|
+
const newAccessKeyId = updatedProject.oAuth2Access.find(
|
|
98
|
+
(access) => access.clientId === projectAccess.clientId
|
|
99
|
+
);
|
|
100
|
+
if (!newAccessKeyId) {
|
|
101
|
+
throw new GenericError("ACCESS_KEY_CREATION_FAILED", {
|
|
102
|
+
accessKeyData: updatedProject.oAuth2Access,
|
|
103
|
+
projectId
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return newAccessKeyId;
|
|
107
|
+
};
|
|
108
|
+
export {
|
|
109
|
+
addNewAccessKey,
|
|
110
|
+
deleteAccessKey,
|
|
111
|
+
refreshAccessKey
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=projectAccessKey.service.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/projectAccessKey.service.ts"],"sourcesContent":["import { ProjectModel } from '@models/project.model';\nimport { GenericError } from '@utils/errors';\nimport type { ObjectId } from 'mongoose';\nimport { generateClientCredentials } from './oAuth2.service';\nimport { getProjectById } from './project.service';\nimport type {\n AccessKeyData,\n OAuth2Access,\n OAuth2AccessData,\n Project,\n} from '@/types/project.types';\nimport { User } from '@/types/user.types';\n\n/**\n * Adds a new access key to a project.\n *\n * @param accessKeyData - The access key data.\n * @param projectId - The ID of the project to add the access key to.\n * @param user - The user adding the access key.\n * @returns The new access key.\n *\n */\nexport const addNewAccessKey = async (\n accessKeyData: AccessKeyData,\n projectId: string | ObjectId,\n user: User\n): Promise<OAuth2Access> => {\n const { clientId, clientSecret } = generateClientCredentials();\n\n const newAccessKey: OAuth2AccessData = {\n ...accessKeyData,\n clientId,\n clientSecret,\n userId: user._id,\n accessToken: [],\n };\n\n const result = await ProjectModel.updateOne(\n { _id: projectId },\n { $push: { oAuth2Access: newAccessKey } }\n );\n\n if (result.modifiedCount === 0) {\n throw new GenericError('ACCESS_KEY_CREATION_FAILED', {\n accessKeyData,\n projectId,\n userId: user._id,\n });\n }\n\n const updatedProject = await getProjectById(projectId);\n\n const newAccessKeyId = updatedProject.oAuth2Access.find(\n (access) => access.clientId === clientId\n );\n\n if (!newAccessKeyId) {\n throw new GenericError('ACCESS_KEY_CREATION_FAILED', {\n accessKeyData,\n projectId,\n userId: user._id,\n });\n }\n\n return newAccessKeyId;\n};\n\nexport const deleteAccessKey = async (\n clientId: string | ObjectId,\n project: Project\n) => {\n const projectAccess = project.oAuth2Access.find(\n (access) => access.clientId === clientId\n );\n\n if (!projectAccess) {\n throw new GenericError('ACCESS_KEY_NOT_FOUND', {\n clientId,\n projectId: project._id,\n });\n }\n\n const result = await ProjectModel.updateOne(\n { 'oAuth2Access.clientId': clientId },\n { $pull: { oAuth2Access: { clientId } } }\n );\n\n if (result.modifiedCount === 0) {\n throw new GenericError('ACCESS_KEY_DELETION_FAILED', {\n clientId,\n projectId: project._id,\n });\n }\n\n return projectAccess;\n};\n\nexport const refreshAccessKey = async (\n clientId: string | ObjectId,\n projectId: string | ObjectId\n): Promise<OAuth2Access> => {\n const project = await ProjectModel.findOne({\n _id: projectId,\n 'oAuth2Access.clientId': clientId,\n });\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_FOUND', {\n clientId,\n projectId,\n });\n }\n\n const projectAccess = project.oAuth2Access.find(\n (access) => access.clientId === clientId\n );\n\n if (!projectAccess) {\n throw new GenericError('ACCESS_KEY_NOT_FOUND', {\n clientId,\n projectId: project._id,\n });\n }\n\n const { clientSecret } = generateClientCredentials();\n\n const result = await ProjectModel.updateOne(\n { 'oAuth2Access.clientId': clientId },\n {\n $set: {\n 'oAuth2Access.$.clientId': projectAccess.clientId,\n 'oAuth2Access.$.clientSecret': clientSecret,\n },\n }\n );\n\n if (result.modifiedCount === 0) {\n throw new GenericError('ACCESS_KEy_UPDATE_FAILED', {\n clientId,\n projectId,\n });\n }\n\n const updatedProject = await getProjectById(projectId);\n\n const newAccessKeyId = updatedProject.oAuth2Access.find(\n (access) => access.clientId === projectAccess.clientId\n );\n\n if (!newAccessKeyId) {\n throw new GenericError('ACCESS_KEY_CREATION_FAILED', {\n accessKeyData: updatedProject.oAuth2Access,\n projectId,\n });\n }\n\n return newAccessKeyId;\n};\n"],"mappings":"AAAA,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAE7B,SAAS,iCAAiC;AAC1C,SAAS,sBAAsB;AAkBxB,MAAM,kBAAkB,OAC7B,eACA,WACA,SAC0B;AAC1B,QAAM,EAAE,UAAU,aAAa,IAAI,0BAA0B;AAE7D,QAAM,eAAiC;AAAA,IACrC,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,QAAQ,KAAK;AAAA,IACb,aAAa,CAAC;AAAA,EAChB;AAEA,QAAM,SAAS,MAAM,aAAa;AAAA,IAChC,EAAE,KAAK,UAAU;AAAA,IACjB,EAAE,OAAO,EAAE,cAAc,aAAa,EAAE;AAAA,EAC1C;AAEA,MAAI,OAAO,kBAAkB,GAAG;AAC9B,UAAM,IAAI,aAAa,8BAA8B;AAAA,MACnD;AAAA,MACA;AAAA,MACA,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAEA,QAAM,iBAAiB,MAAM,eAAe,SAAS;AAErD,QAAM,iBAAiB,eAAe,aAAa;AAAA,IACjD,CAAC,WAAW,OAAO,aAAa;AAAA,EAClC;AAEA,MAAI,CAAC,gBAAgB;AACnB,UAAM,IAAI,aAAa,8BAA8B;AAAA,MACnD;AAAA,MACA;AAAA,MACA,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAEO,MAAM,kBAAkB,OAC7B,UACA,YACG;AACH,QAAM,gBAAgB,QAAQ,aAAa;AAAA,IACzC,CAAC,WAAW,OAA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