Merge pull request #2037 from automatisch/refactor-async-errors

refactor: Use express-async-errors instead of express-async-handler
This commit is contained in:
Ömer Faruk Aydın
2024-08-28 12:13:22 +03:00
committed by GitHub
22 changed files with 68 additions and 157 deletions

View File

@@ -39,7 +39,7 @@
"debug": "~2.6.9",
"dotenv": "^10.0.0",
"express": "~4.18.2",
"express-async-handler": "^1.2.0",
"express-async-errors": "^3.1.1",
"express-basic-auth": "^1.2.1",
"express-graphql": "^0.12.0",
"fast-xml-parser": "^4.0.11",
@@ -107,7 +107,9 @@
"access": "public"
},
"nodemonConfig": {
"watch": [ "src/" ],
"watch": [
"src/"
],
"ext": "js"
}
}

View File

@@ -1,5 +1,6 @@
import createError from 'http-errors';
import express from 'express';
import 'express-async-errors';
import cors from 'cors';
import appConfig from './config/app.js';

View File

@@ -1,16 +1,11 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import createAccessTokenAction from '../../../controllers/api/v1/access-tokens/create-access-token.js';
import revokeAccessTokenAction from '../../../controllers/api/v1/access-tokens/revoke-access-token.js';
import { authenticateUser } from '../../../helpers/authentication.js';
const router = Router();
router.post('/', asyncHandler(createAccessTokenAction));
router.post('/', createAccessTokenAction);
router.delete(
'/:token',
authenticateUser,
asyncHandler(revokeAccessTokenAction)
);
router.delete('/:token', authenticateUser, revokeAccessTokenAction);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../../helpers/authentication.js';
import { authorizeAdmin } from '../../../../helpers/authorization.js';
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
@@ -24,7 +23,7 @@ router.get(
authenticateUser,
authorizeAdmin,
checkIsEnterprise,
asyncHandler(getAuthClientsAction)
getAuthClientsAction
);
router.post(
@@ -32,7 +31,7 @@ router.post(
authenticateUser,
authorizeAdmin,
checkIsEnterprise,
asyncHandler(createAuthClientAction)
createAuthClientAction
);
router.get(
@@ -40,7 +39,7 @@ router.get(
authenticateUser,
authorizeAdmin,
checkIsEnterprise,
asyncHandler(getAuthClientAction)
getAuthClientAction
);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../../helpers/authentication.js';
import { authorizeAdmin } from '../../../../helpers/authorization.js';
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
@@ -12,7 +11,7 @@ router.get(
authenticateUser,
authorizeAdmin,
checkIsEnterprise,
asyncHandler(getPermissionsCatalogAction)
getPermissionsCatalogAction
);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../../helpers/authentication.js';
import { authorizeAdmin } from '../../../../helpers/authorization.js';
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
@@ -13,7 +12,7 @@ router.get(
authenticateUser,
authorizeAdmin,
checkIsEnterprise,
asyncHandler(getRolesAction)
getRolesAction
);
router.get(
@@ -21,7 +20,7 @@ router.get(
authenticateUser,
authorizeAdmin,
checkIsEnterprise,
asyncHandler(getRoleAction)
getRoleAction
);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../../helpers/authentication.js';
import { authorizeAdmin } from '../../../../helpers/authorization.js';
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
@@ -14,7 +13,7 @@ router.get(
authenticateUser,
authorizeAdmin,
checkIsEnterprise,
asyncHandler(getSamlAuthProvidersAction)
getSamlAuthProvidersAction
);
router.get(
@@ -22,7 +21,7 @@ router.get(
authenticateUser,
authorizeAdmin,
checkIsEnterprise,
asyncHandler(getSamlAuthProviderAction)
getSamlAuthProviderAction
);
router.get(
@@ -30,7 +29,7 @@ router.get(
authenticateUser,
authorizeAdmin,
checkIsEnterprise,
asyncHandler(getRoleMappingsAction)
getRoleMappingsAction
);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../../helpers/authentication.js';
import { authorizeAdmin } from '../../../../helpers/authorization.js';
import getUsersAction from '../../../../controllers/api/v1/admin/users/get-users.ee.js';
@@ -8,20 +7,8 @@ import deleteUserAction from '../../../../controllers/api/v1/admin/users/delete-
const router = Router();
router.get('/', authenticateUser, authorizeAdmin, asyncHandler(getUsersAction));
router.get(
'/:userId',
authenticateUser,
authorizeAdmin,
asyncHandler(getUserAction)
);
router.delete(
'/:userId',
authenticateUser,
authorizeAdmin,
asyncHandler(deleteUserAction)
);
router.get('/', authenticateUser, authorizeAdmin, getUsersAction);
router.get('/:userId', authenticateUser, authorizeAdmin, getUserAction);
router.delete('/:userId', authenticateUser, authorizeAdmin, deleteUserAction);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../helpers/authentication.js';
import { authorizeUser } from '../../../helpers/authorization.js';
import { checkIsEnterprise } from '../../../helpers/check-is-enterprise.js';
@@ -18,67 +17,54 @@ import getFlowsAction from '../../../controllers/api/v1/apps/get-flows.js';
const router = Router();
router.get('/', authenticateUser, asyncHandler(getAppsAction));
router.get('/:appKey', authenticateUser, asyncHandler(getAppAction));
router.get('/:appKey/auth', authenticateUser, asyncHandler(getAuthAction));
router.get('/', authenticateUser, getAppsAction);
router.get('/:appKey', authenticateUser, getAppAction);
router.get('/:appKey/auth', authenticateUser, getAuthAction);
router.get(
'/:appKey/connections',
authenticateUser,
authorizeUser,
asyncHandler(getConnectionsAction)
getConnectionsAction
);
router.get(
'/:appKey/config',
authenticateUser,
checkIsEnterprise,
asyncHandler(getConfigAction)
getConfigAction
);
router.get(
'/:appKey/auth-clients',
authenticateUser,
checkIsEnterprise,
asyncHandler(getAuthClientsAction)
getAuthClientsAction
);
router.get(
'/:appKey/auth-clients/:appAuthClientId',
authenticateUser,
checkIsEnterprise,
asyncHandler(getAuthClientAction)
getAuthClientAction
);
router.get(
'/:appKey/triggers',
authenticateUser,
asyncHandler(getTriggersAction)
);
router.get('/:appKey/triggers', authenticateUser, getTriggersAction);
router.get(
'/:appKey/triggers/:triggerKey/substeps',
authenticateUser,
asyncHandler(getTriggerSubstepsAction)
getTriggerSubstepsAction
);
router.get(
'/:appKey/actions',
authenticateUser,
asyncHandler(getActionsAction)
);
router.get('/:appKey/actions', authenticateUser, getActionsAction);
router.get(
'/:appKey/actions/:actionKey/substeps',
authenticateUser,
asyncHandler(getActionSubstepsAction)
getActionSubstepsAction
);
router.get(
'/:appKey/flows',
authenticateUser,
authorizeUser,
asyncHandler(getFlowsAction)
);
router.get('/:appKey/flows', authenticateUser, authorizeUser, getFlowsAction);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { checkIsEnterprise } from '../../../helpers/check-is-enterprise.js';
import versionAction from '../../../controllers/api/v1/automatisch/version.js';
import notificationsAction from '../../../controllers/api/v1/automatisch/notifications.js';
@@ -9,10 +8,10 @@ import configAction from '../../../controllers/api/v1/automatisch/config.ee.js';
const router = Router();
router.get('/version', asyncHandler(versionAction));
router.get('/notifications', asyncHandler(notificationsAction));
router.get('/info', asyncHandler(infoAction));
router.get('/license', asyncHandler(licenseAction));
router.get('/config', checkIsEnterprise, asyncHandler(configAction));
router.get('/version', versionAction);
router.get('/notifications', notificationsAction);
router.get('/info', infoAction);
router.get('/license', licenseAction);
router.get('/config', checkIsEnterprise, configAction);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../helpers/authentication.js';
import { authorizeUser } from '../../../helpers/authorization.js';
import getFlowsAction from '../../../controllers/api/v1/connections/get-flows.js';
@@ -12,21 +11,21 @@ router.get(
'/:connectionId/flows',
authenticateUser,
authorizeUser,
asyncHandler(getFlowsAction)
getFlowsAction
);
router.post(
'/:connectionId/test',
authenticateUser,
authorizeUser,
asyncHandler(testConnectionAction)
testConnectionAction
);
router.post(
'/:connectionId/verify',
authenticateUser,
authorizeUser,
asyncHandler(verifyConnectionAction)
verifyConnectionAction
);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../helpers/authentication.js';
import { authorizeUser } from '../../../helpers/authorization.js';
import getExecutionsAction from '../../../controllers/api/v1/executions/get-executions.js';
@@ -8,25 +7,20 @@ import getExecutionStepsAction from '../../../controllers/api/v1/executions/get-
const router = Router();
router.get(
'/',
authenticateUser,
authorizeUser,
asyncHandler(getExecutionsAction)
);
router.get('/', authenticateUser, authorizeUser, getExecutionsAction);
router.get(
'/:executionId',
authenticateUser,
authorizeUser,
asyncHandler(getExecutionAction)
getExecutionAction
);
router.get(
'/:executionId/execution-steps',
authenticateUser,
authorizeUser,
asyncHandler(getExecutionStepsAction)
getExecutionStepsAction
);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../helpers/authentication.js';
import { authorizeUser } from '../../../helpers/authorization.js';
import getFlowsAction from '../../../controllers/api/v1/flows/get-flows.js';
@@ -7,13 +6,7 @@ import getFlowAction from '../../../controllers/api/v1/flows/get-flow.js';
const router = Router();
router.get('/', authenticateUser, authorizeUser, asyncHandler(getFlowsAction));
router.get(
'/:flowId',
authenticateUser,
authorizeUser,
asyncHandler(getFlowAction)
);
router.get('/', authenticateUser, authorizeUser, getFlowsAction);
router.get('/:flowId', authenticateUser, authorizeUser, getFlowAction);
export default router;

View File

@@ -1,14 +1,9 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { allowInstallation } from '../../../../helpers/allow-installation.js';
import createUserAction from '../../../../controllers/api/v1/installation/users/create-user.js';
const router = Router();
router.post(
'/',
allowInstallation,
asyncHandler(createUserAction)
);
router.post('/', allowInstallation, createUserAction);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../helpers/authentication.js';
import checkIsCloud from '../../../helpers/check-is-cloud.js';
import getPlansAction from '../../../controllers/api/v1/payment/get-plans.ee.js';
@@ -7,18 +6,7 @@ import getPaddleInfoAction from '../../../controllers/api/v1/payment/get-paddle-
const router = Router();
router.get(
'/plans',
authenticateUser,
checkIsCloud,
asyncHandler(getPlansAction)
);
router.get(
'/paddle-info',
authenticateUser,
checkIsCloud,
asyncHandler(getPaddleInfoAction)
);
router.get('/plans', authenticateUser, checkIsCloud, getPlansAction);
router.get('/paddle-info', authenticateUser, checkIsCloud, getPaddleInfoAction);
export default router;

View File

@@ -1,10 +1,9 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { checkIsEnterprise } from '../../../helpers/check-is-enterprise.js';
import getSamlAuthProvidersAction from '../../../controllers/api/v1/saml-auth-providers/get-saml-auth-providers.ee.js';
const router = Router();
router.get('/', checkIsEnterprise, asyncHandler(getSamlAuthProvidersAction));
router.get('/', checkIsEnterprise, getSamlAuthProvidersAction);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../helpers/authentication.js';
import { authorizeUser } from '../../../helpers/authorization.js';
import getConnectionAction from '../../../controllers/api/v1/steps/get-connection.js';
@@ -14,35 +13,30 @@ router.get(
'/:stepId/connection',
authenticateUser,
authorizeUser,
asyncHandler(getConnectionAction)
getConnectionAction
);
router.get(
'/:stepId/previous-steps',
authenticateUser,
authorizeUser,
asyncHandler(getPreviousStepsAction)
getPreviousStepsAction
);
router.post(
'/:stepId/dynamic-fields',
authenticateUser,
authorizeUser,
asyncHandler(createDynamicFieldsAction)
createDynamicFieldsAction
);
router.post(
'/:stepId/dynamic-data',
authenticateUser,
authorizeUser,
asyncHandler(createDynamicDataAction)
createDynamicDataAction
);
router.delete(
'/:stepId',
authenticateUser,
authorizeUser,
asyncHandler(deleteStepAction)
);
router.delete('/:stepId', authenticateUser, authorizeUser, deleteStepAction);
export default router;

View File

@@ -1,5 +1,4 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../helpers/authentication.js';
import { authorizeUser } from '../../../helpers/authorization.js';
import checkIsCloud from '../../../helpers/check-is-cloud.js';
@@ -15,46 +14,33 @@ import resetPasswordAction from '../../../controllers/api/v1/users/reset-passwor
const router = Router();
router.get('/me', authenticateUser, asyncHandler(getCurrentUserAction));
router.get(
'/:userId/apps',
authenticateUser,
authorizeUser,
asyncHandler(getAppsAction)
);
router.get(
'/invoices',
authenticateUser,
checkIsCloud,
asyncHandler(getInvoicesAction)
);
router.get('/me', authenticateUser, getCurrentUserAction);
router.get('/:userId/apps', authenticateUser, authorizeUser, getAppsAction);
router.get('/invoices', authenticateUser, checkIsCloud, getInvoicesAction);
router.get(
'/:userId/trial',
authenticateUser,
checkIsCloud,
asyncHandler(getUserTrialAction)
getUserTrialAction
);
router.get(
'/:userId/subscription',
authenticateUser,
checkIsCloud,
asyncHandler(getSubscriptionAction)
getSubscriptionAction
);
router.get(
'/:userId/plan-and-usage',
authenticateUser,
checkIsCloud,
asyncHandler(getPlanAndUsageAction)
getPlanAndUsageAction
);
router.post('/invitation', asyncHandler(acceptInvitationAction));
router.post('/forgot-password', asyncHandler(forgotPasswordAction));
router.post('/reset-password', asyncHandler(resetPasswordAction));
router.post('/invitation', acceptInvitationAction);
router.post('/forgot-password', forgotPasswordAction);
router.post('/reset-password', resetPasswordAction);
export default router;

View File

@@ -1,9 +1,8 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import indexAction from '../controllers/healthcheck/index.js';
const router = Router();
router.get('/', asyncHandler(indexAction));
router.get('/', indexAction);
export default router;

View File

@@ -43,5 +43,4 @@ router.use('/api/v1/admin/permissions', permissionsRouter);
router.use('/api/v1/admin/saml-auth-providers', adminSamlAuthProvidersRouter);
router.use('/api/v1/installation/users', installationUsersRouter);
export default router;

View File

@@ -1,9 +1,8 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import webhooksHandler from '../controllers/paddle/webhooks.ee.js';
const router = Router();
router.post('/webhooks', asyncHandler(webhooksHandler));
router.post('/webhooks', webhooksHandler);
export default router;

View File

@@ -8551,10 +8551,10 @@ exponential-backoff@^3.1.1:
resolved "https://registry.yarnpkg.com/exponential-backoff/-/exponential-backoff-3.1.1.tgz#64ac7526fe341ab18a39016cd22c787d01e00bf6"
integrity sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw==
express-async-handler@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/express-async-handler/-/express-async-handler-1.2.0.tgz#ffc9896061d90f8d2e71a2d2b8668db5b0934391"
integrity sha512-rCSVtPXRmQSW8rmik/AIb2P0op6l7r1fMW538yyvTMltCO4xQEWMmobfrIxN2V1/mVrgxB8Az3reYF6yUZw37w==
express-async-errors@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/express-async-errors/-/express-async-errors-3.1.1.tgz#6053236d61d21ddef4892d6bd1d736889fc9da41"
integrity sha512-h6aK1da4tpqWSbyCa3FxB/V6Ehd4EEB15zyQq9qe75OZBp0krinNKuH4rAY+S/U/2I36vdLAUFSjQJ+TFmODng==
express-basic-auth@^1.2.1:
version "1.2.1"