Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
chore: audit for responses. remove unused mgmt apis
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkit committed Oct 10, 2023
1 parent 0cee6d1 commit 36dccb1
Show file tree
Hide file tree
Showing 89 changed files with 830 additions and 2,950 deletions.
12 changes: 12 additions & 0 deletions apps/api/middleware/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { logger } from '@/../../packages/core/lib/logger';
import type { NextFunction, Request, Response } from 'express';
import * as OpenApiValidator from 'express-openapi-validator';
import fs from 'fs';
Expand Down Expand Up @@ -39,6 +40,17 @@ export const openapiMiddleware = (specDir: string, version = 'v2') => {
validateRequests: {
removeAdditional: true,
},
validateResponses: {
onError: (error, body, req) => {
logger.error(
{
error,
originalUrl: req.originalUrl,
},
'API reference validation error'
);
},
},
});
};

Expand Down
5 changes: 0 additions & 5 deletions apps/api/routes/mgmt/v2/customer/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ export default function init(app: Router): void {
req.supaglueApplication.id
);

// enrich with user_id, if we can.
// TODO remove this after users migrate to /_provider_user_id above
const [client] = await remoteService.getCrmRemoteClient(req.params.connection_id);
const { userId } = await client.getUserIdAndDetails();

return res.status(200).send(snakecaseKeys({ ...connection, userId }));
}
);
Expand Down
78 changes: 0 additions & 78 deletions apps/api/routes/mgmt/v2/destination/index.ts

This file was deleted.

3 changes: 3 additions & 0 deletions apps/api/routes/mgmt/v2/entity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { Router } from 'express';

const { entityService } = getDependencyContainer();

/**
* @deprecated
*/
export default function init(app: Router): void {
const entityRouter = Router({ mergeParams: true });

Expand Down
4 changes: 0 additions & 4 deletions apps/api/routes/mgmt/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import { pinoAndSentryContextMiddleware } from '@/middleware/pino_context';
import { Router } from 'express';
import connectionSyncConfig from './connection_sync_config';
import customer from './customer';
import destination from './destination';
import entity from './entity';
import entityMapping from './entity_mapping';
import fieldMapping from './field_mapping';
import magicLink from './magic_link';
import provider from './provider';
import schema from './schema';
import sync from './sync';
import syncConfig from './sync_config';
Expand All @@ -23,8 +21,6 @@ export default function init(app: Router): void {
v2Router.use(pinoAndSentryContextMiddleware);

customer(v2Router);
destination(v2Router);
provider(v2Router);
schema(v2Router);
syncConfig(v2Router);
sync(v2Router);
Expand Down
97 changes: 0 additions & 97 deletions apps/api/routes/mgmt/v2/provider/index.ts

This file was deleted.

84 changes: 0 additions & 84 deletions apps/api/routes/mgmt/v2/sync_config/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { getDependencyContainer } from '@/dependency_container';
import type {
CreateSyncConfigPathParams,
CreateSyncConfigRequest,
CreateSyncConfigResponse,
DeleteSyncConfigPathParams,
DeleteSyncConfigRequest,
DeleteSyncConfigResponse,
GetSyncConfigPathParams,
GetSyncConfigRequest,
GetSyncConfigResponse,
GetSyncConfigsPathParams,
GetSyncConfigsRequest,
GetSyncConfigsResponse,
UpdateSyncConfigPathParams,
UpdateSyncConfigRequest,
UpdateSyncConfigResponse,
} from '@supaglue/schemas/v2/mgmt';
import type { CommonObjectType } from '@supaglue/types';
import { camelcaseKeys } from '@supaglue/utils/camelcase';
import { snakecaseKeys } from '@supaglue/utils/snakecase';
import type { Request, Response } from 'express';
import { Router } from 'express';
Expand All @@ -38,75 +24,5 @@ export default function init(app: Router): void {
}
);

syncConfigRouter.post(
'/',
async (
req: Request<CreateSyncConfigPathParams, CreateSyncConfigResponse, CreateSyncConfigRequest>,
res: Response<CreateSyncConfigResponse>
) => {
const syncConfig = await syncConfigService.create({
applicationId: req.supaglueApplication.id,
...camelcaseKeys({
...req.body,
config: {
...req.body.config,
common_objects: req.body.config.common_objects?.map((commonObject) => ({
...commonObject,
object: commonObject.object as CommonObjectType,
})),
},
}),
});
return res.status(201).send(snakecaseKeys(syncConfig));
}
);

syncConfigRouter.get(
'/:sync_config_id',
async (
req: Request<GetSyncConfigPathParams, GetSyncConfigResponse, GetSyncConfigRequest>,
res: Response<GetSyncConfigResponse>
) => {
const syncConfig = await syncConfigService.getByIdAndApplicationId(
req.params.sync_config_id,
req.supaglueApplication.id
);
return res.status(200).send(snakecaseKeys(syncConfig));
}
);

syncConfigRouter.put(
'/:sync_config_id',
async (
req: Request<UpdateSyncConfigPathParams, UpdateSyncConfigResponse, UpdateSyncConfigRequest>,
res: Response<UpdateSyncConfigResponse>
) => {
const syncConfig = await syncConfigService.update(req.params.sync_config_id, req.supaglueApplication.id, {
...camelcaseKeys({
...req.body,
config: {
...req.body.config,
common_objects: req.body.config.common_objects?.map((commonObject) => ({
...commonObject,
object: commonObject.object as CommonObjectType,
})),
},
}),
});
return res.status(200).send(snakecaseKeys(syncConfig));
}
);

syncConfigRouter.delete(
'/:sync_config_id',
async (
req: Request<DeleteSyncConfigPathParams, DeleteSyncConfigResponse, DeleteSyncConfigRequest>,
res: Response<DeleteSyncConfigResponse>
) => {
await syncConfigService.delete(req.params.sync_config_id, req.supaglueApplication.id);
return res.status(204).end();
}
);

app.use('/sync_configs', syncConfigRouter);
}
21 changes: 17 additions & 4 deletions docs/docs/api/v2/mgmt/create-connection.api.mdx

Large diffs are not rendered by default.

Loading

0 comments on commit 36dccb1

Please sign in to comment.