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

Commit e871659

Browse files
committed
chore: Refactor the supaglue client to also use the new createOpenapiClient
1 parent b6af29a commit e871659

File tree

12 files changed

+47
-30
lines changed

12 files changed

+47
-30
lines changed

apps/api/routes/engagement/v2/sequence.integration.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @jest-environment ./integration-test-environment
66
*/
77

8+
import { HTTPError } from '@supaglue/schemas';
89
import type {
910
CreateContactRequest,
1011
CreateContactResponse,
@@ -92,17 +93,18 @@ describe('sequence', () => {
9293
test(`Error body`, async () => {
9394
testSequence.steps[0].interval_seconds = 123;
9495

95-
const res = await supaglueClient.engagement.POST('/sequences', {
96-
body: { record: testSequence },
97-
// TODO: Make it so that x-customer-id can be omitted if it was passed into the client at creation time.
98-
params: { header: { 'x-provider-name': 'salesloft', 'x-customer-id': process.env.CUSTOMER_ID! } },
99-
});
96+
const res = (await supaglueClient.engagement
97+
.POST('/sequences', {
98+
body: { record: testSequence },
99+
// TODO: Make it so that x-customer-id can be omitted if it was passed into the client at creation time.
100+
params: { header: { 'x-provider-name': 'salesloft', 'x-customer-id': process.env.CUSTOMER_ID! } },
101+
})
102+
.catch((e) => e as HTTPError<unknown>)) as HTTPError<unknown>;
100103

104+
expect(res).toBeInstanceOf(HTTPError);
101105
expect(res.response.status).toEqual(400);
102106
// Our API spec is wrong and should specify 400 return code with ability to have errors
103-
expect((res.error as typeof res.data)?.errors?.[0].title).toMatch(
104-
'Salesloft only supports intervals in whole days'
105-
);
107+
expect((res.error as any)?.errors?.[0].title).toMatch('Salesloft only supports intervals in whole days');
106108
});
107109

108110
describe.each(['outreach', 'apollo', 'salesloft'])('%s', (providerName) => {

packages/core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"@types/uuid": "^9.0.1",
4949
"concurrently": "^8.2.2",
5050
"openapi-typescript": "^6.7.1",
51-
"openapi-typescript-helpers": "0.0.4",
5251
"prettier": "^3.1.0",
5352
"ts-toolbelt": "9.6.0",
5453
"typescript": "^4.9.5"

packages/core/remotes/impl/apollo/apollo.client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createOpenapiClient } from '../../utils/createOpenapiClient';
1+
import { createOpenapiClient } from '@supaglue/schemas';
22

33
import type { paths } from './apollo.openapi.gen';
44
import oas from './apollo.openapi.json';

packages/core/remotes/impl/apollo/apollo.openapi.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/remotes/impl/apollo/apollo.openapi.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ export function outputOpenApi() {
211211
openapi: '3.1.0',
212212
info: { title: 'Apollo API', version: '0.0.0' },
213213
servers: [{ url: 'https://app.apollo.io/api' }],
214+
security: [{ api_key: [] }],
215+
components: {
216+
securitySchemes: { api_key: { type: 'apiKey', name: 'api_key', in: 'query' } },
217+
},
214218
paths: {
215219
'/v1/emailer_campaigns/{id}': {
216220
get: jsonOperation('getEmailerCampaign', {

packages/core/remotes/impl/outreach/outreach.client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { OAuthClientOptions } from '@supaglue/schemas';
2+
import { createOpenapiOauthClient, HTTPError } from '@supaglue/schemas';
13
import { SGConnectionNoLongerAuthenticatedError } from '../../../errors';
2-
import type { OAuthClientOptions } from '../../utils/createOpenapiClient';
3-
import { createOpenapiOauthClient, HTTPError } from '../../utils/createOpenapiClient';
44

55
import type { paths } from './outreach.openapi.gen';
66
import oas from './outreach.openapi.json';

packages/core/remotes/impl/salesloft/salesloft.client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { OAuthClientOptions } from '@supaglue/schemas';
2+
import { createOpenapiOauthClient } from '@supaglue/schemas';
13
import type { ConnectorAuthConfig } from '../../base';
2-
import type { OAuthClientOptions } from '../../utils/createOpenapiClient';
3-
import { createOpenapiOauthClient } from '../../utils/createOpenapiClient';
44

55
import type { paths } from './salesloft.openapi.gen';
66
import oas from './salesloft.openapi.json';

packages/core/remotes/utils/createOpenapiClient.ts renamed to packages/schemas/createOpenapiClient.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { FetchOptions, FetchResponse } from 'openapi-fetch';
22
import createClient from 'openapi-fetch';
3-
// @ts-expect-error Not sure we get The current file is a CommonJS module whose imports will
4-
// produce 'require' calls error, but it's ireelevant and thus we will suppress it
3+
// @ts-expect-error Not sure why this is needed
54
import type { PathsWithMethod } from 'openapi-typescript-helpers';
65

76
type HTTPMethod = 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH' | 'TRACE';

packages/schemas/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './supaglue-client';
2+
export * from './createOpenapiClient'

packages/schemas/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"devDependencies": {
1111
"openapi-typescript": "^6.7.0",
12+
"openapi-typescript-helpers": "^0.0.4",
1213
"tsx": "^3.12.3"
1314
}
1415
}

0 commit comments

Comments
 (0)