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

Commit 3cd6151

Browse files
author
Ryan Liu
authored
feat: application endpoints, nesting, open API (#243)
* create `/application` CRUD endpoints + openAPI specs * nest all mgmt routes under `/applications/{application_id}` * regenerate types + SDK
1 parent d46f0d9 commit 3cd6151

File tree

142 files changed

+5910
-722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+5910
-722
lines changed

apps/api/routes/crm/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { connectionHeaderMiddleware } from '@/middleware/connection';
12
import { Router } from 'express';
23
import v1 from './v1';
34

45
export default function init(app: Router): void {
56
const crmRouter = Router();
7+
crmRouter.use(connectionHeaderMiddleware);
68

79
v1(crmRouter);
810

apps/api/routes/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { connectionHeaderMiddleware } from '@/middleware/connection';
21
import { Router } from 'express';
32
import crm from './crm';
43
import mgmt from './mgmt';
@@ -7,10 +6,5 @@ import oauth from './oauth';
76
export default function initRoutes(app: Router): void {
87
oauth(app);
98
mgmt(app);
10-
11-
const crmRouter = Router();
12-
crmRouter.use(connectionHeaderMiddleware);
13-
crm(crmRouter);
14-
15-
app.use(crmRouter);
9+
crm(app);
1610
}

apps/api/routes/mgmt/v1/customer/index.ts renamed to apps/api/routes/mgmt/v1/application/customer/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ export default function init(app: Router): void {
6767
}
6868
);
6969

70-
connection(customerRouter);
71-
7270
app.use('/customers', customerRouter);
71+
72+
const perCustomerRouter = Router({ mergeParams: true });
73+
74+
connection(perCustomerRouter);
75+
customerRouter.use('/:customer_id', perCustomerRouter);
7376
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { getDependencyContainer } from '@/dependency_container';
2+
import { camelcaseKeys } from '@/lib/camelcase';
3+
import { snakecaseKeys } from '@/lib/snakecase';
4+
import {
5+
CreateApplicationPathParams,
6+
CreateApplicationRequest,
7+
CreateApplicationResponse,
8+
DeleteApplicationPathParams,
9+
DeleteApplicationRequest,
10+
DeleteApplicationResponse,
11+
GetApplicationPathParams,
12+
GetApplicationRequest,
13+
GetApplicationResponse,
14+
GetApplicationsPathParams,
15+
GetApplicationsRequest,
16+
GetApplicationsResponse,
17+
UpdateApplicationPathParams,
18+
UpdateApplicationRequest,
19+
UpdateApplicationResponse,
20+
} from '@supaglue/schemas/mgmt';
21+
import { Request, Response, Router } from 'express';
22+
import customer from './customer';
23+
import integration from './integration';
24+
25+
const { applicationService } = getDependencyContainer();
26+
27+
export default function init(app: Router): void {
28+
const applicationRouter = Router();
29+
30+
applicationRouter.get(
31+
'/',
32+
async (
33+
req: Request<GetApplicationsPathParams, GetApplicationsResponse, GetApplicationsRequest>,
34+
res: Response<GetApplicationsResponse>
35+
) => {
36+
const applications = await applicationService.list();
37+
// TODO: Figure out why typing doesn't work here
38+
return res.status(200).send(applications.map(snakecaseKeys) as GetApplicationsResponse);
39+
}
40+
);
41+
42+
applicationRouter.post(
43+
'/',
44+
async (
45+
req: Request<CreateApplicationPathParams, CreateApplicationResponse, CreateApplicationRequest>,
46+
res: Response<CreateApplicationResponse>
47+
) => {
48+
const application = await applicationService.create(camelcaseKeys(req.body));
49+
// TODO: Figure out why typing doesn't work here
50+
return res.status(201).send(snakecaseKeys(application) as CreateApplicationResponse);
51+
}
52+
);
53+
54+
applicationRouter.get(
55+
'/:application_id',
56+
async (
57+
req: Request<GetApplicationPathParams, GetApplicationResponse, GetApplicationRequest>,
58+
res: Response<GetApplicationResponse>
59+
) => {
60+
const application = await applicationService.getById(req.params.application_id);
61+
// TODO: Figure out why typing doesn't work here
62+
return res.status(200).send(snakecaseKeys(application) as GetApplicationResponse);
63+
}
64+
);
65+
66+
applicationRouter.put(
67+
'/:application_id',
68+
async (
69+
req: Request<UpdateApplicationPathParams, UpdateApplicationResponse, UpdateApplicationRequest>,
70+
res: Response<UpdateApplicationResponse>
71+
) => {
72+
const application = await applicationService.update(req.params.application_id, camelcaseKeys(req.body));
73+
// TODO: Figure out why typing doesn't work here
74+
return res.status(200).send(snakecaseKeys(application) as UpdateApplicationResponse);
75+
}
76+
);
77+
78+
applicationRouter.delete(
79+
'/:application_id',
80+
async (
81+
req: Request<DeleteApplicationPathParams, DeleteApplicationResponse, DeleteApplicationRequest>,
82+
res: Response<DeleteApplicationResponse>
83+
) => {
84+
const application = await applicationService.delete(req.params.application_id);
85+
// TODO: Figure out why typing doesn't work here
86+
return res.status(200).send(snakecaseKeys(application) as DeleteApplicationResponse);
87+
}
88+
);
89+
90+
app.use('/applications', applicationRouter);
91+
92+
const perApplicationRouter = Router({ mergeParams: true });
93+
94+
customer(perApplicationRouter);
95+
integration(perApplicationRouter);
96+
97+
applicationRouter.use(`/:application_id`, perApplicationRouter);
98+
}

apps/api/routes/mgmt/v1/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { openapiMiddleware } from '@/middleware/openapi';
22
import { Router } from 'express';
3-
import customer from './customer';
4-
import integration from './integration';
3+
import application from './application';
54

65
export default function init(app: Router): void {
76
const v1Router = Router();
87

98
v1Router.use(openapiMiddleware('mgmt'));
109

11-
customer(v1Router);
12-
integration(v1Router);
10+
application(v1Router);
1311

1412
app.use('/v1', v1Router);
1513
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type: object
2+
properties:
3+
name:
4+
type: string
5+
example: my-app
6+
config:
7+
$ref: ./objects/application_config.yaml
8+
required:
9+
- name
10+
- config
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
type: object
2+
properties:
3+
id:
4+
type: string
5+
example: e888cedf-e9d0-42c5-9485-2d72984faef2
6+
name:
7+
type: string
8+
example: my-app
9+
config:
10+
$ref: ./application_config.yaml
11+
required:
12+
- id
13+
- name
14+
- config
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
type: object
2+
properties:
3+
webhook:
4+
type: object
5+
nullable: true
6+
properties:
7+
url:
8+
type: string
9+
request_type:
10+
type: string
11+
enum:
12+
- GET
13+
- POST
14+
- PUT
15+
- DELETE
16+
- PATCH
17+
notify_on_sync_success:
18+
type: boolean
19+
notify_on_sync_error:
20+
type: boolean
21+
notify_on_connection_success:
22+
type: boolean
23+
notify_on_connection_error:
24+
type: boolean
25+
headers:
26+
type: object
27+
additionalProperties: true
28+
required:
29+
- url
30+
- request_type
31+
- notify_on_sync_success
32+
- notify_on_sync_error
33+
- notify_on_connection_success
34+
- notify_on_connection_error
35+
required:
36+
- webhook

openapi/mgmt/components/schemas/objects/integration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ required:
3030
# auth_type: oauth2
3131
# provider_name: hubspot
3232
# config:
33-
# - remote_provider_app_id: my_app_id
33+
# - provider_app_id: my_app_id
3434
# oauth:
3535
# - oauth_scopes:
3636
# - crm.objects.contacts.read

openapi/mgmt/components/schemas/objects/integration_config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type: object
22
properties:
3-
remote_provider_app_id:
3+
provider_app_id:
44
type: string
55
example: my_app_id
66
oauth:
@@ -35,11 +35,11 @@ properties:
3535
required:
3636
- period_ms
3737
required:
38-
- remote_provider_app_id
38+
- provider_app_id
3939
- oauth
4040
- sync
4141
example:
42-
- remote_provider_app_id: my_app_id
42+
- provider_app_id: my_app_id
4343
- oauth:
4444
- oauth_scopes:
4545
- crm.objects.contacts.read

0 commit comments

Comments
 (0)