diff --git a/apps/api/routes/engagement/v2/sequence.integration.test.ts b/apps/api/routes/engagement/v2/sequence.integration.test.ts index 7720984f8..05a0b5476 100644 --- a/apps/api/routes/engagement/v2/sequence.integration.test.ts +++ b/apps/api/routes/engagement/v2/sequence.integration.test.ts @@ -5,6 +5,7 @@ * @jest-environment ./integration-test-environment */ +import { HTTPError } from '@supaglue/schemas'; import type { CreateContactRequest, CreateContactResponse, @@ -92,17 +93,18 @@ describe('sequence', () => { test(`Error body`, async () => { testSequence.steps[0].interval_seconds = 123; - const res = await supaglueClient.engagement.POST('/sequences', { - body: { record: testSequence }, - // TODO: Make it so that x-customer-id can be omitted if it was passed into the client at creation time. - params: { header: { 'x-provider-name': 'salesloft', 'x-customer-id': process.env.CUSTOMER_ID! } }, - }); + const res = (await supaglueClient.engagement + .POST('/sequences', { + body: { record: testSequence }, + // TODO: Make it so that x-customer-id can be omitted if it was passed into the client at creation time. + params: { header: { 'x-provider-name': 'salesloft', 'x-customer-id': process.env.CUSTOMER_ID! } }, + }) + .catch((e) => e as HTTPError)) as HTTPError; + expect(res).toBeInstanceOf(HTTPError); expect(res.response.status).toEqual(400); // Our API spec is wrong and should specify 400 return code with ability to have errors - expect((res.error as typeof res.data)?.errors?.[0].title).toMatch( - 'Salesloft only supports intervals in whole days' - ); + expect((res.error as any)?.errors?.[0].title).toMatch('Salesloft only supports intervals in whole days'); }); describe.each(['outreach', 'apollo', 'salesloft'])('%s', (providerName) => { diff --git a/packages/core/package.json b/packages/core/package.json index 3980d5d5f..67fe4be26 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -48,7 +48,6 @@ "@types/uuid": "^9.0.1", "concurrently": "^8.2.2", "openapi-typescript": "^6.7.1", - "openapi-typescript-helpers": "0.0.4", "prettier": "^3.1.0", "ts-toolbelt": "9.6.0", "typescript": "^4.9.5" diff --git a/packages/core/remotes/impl/apollo/apollo.client.ts b/packages/core/remotes/impl/apollo/apollo.client.ts index 02d6edf33..851087301 100644 --- a/packages/core/remotes/impl/apollo/apollo.client.ts +++ b/packages/core/remotes/impl/apollo/apollo.client.ts @@ -1,4 +1,4 @@ -import { createOpenapiClient } from '../../utils/createOpenapiClient'; +import { createOpenapiClient } from '@supaglue/schemas'; import type { paths } from './apollo.openapi.gen'; import oas from './apollo.openapi.json'; diff --git a/packages/core/remotes/impl/apollo/apollo.openapi.json b/packages/core/remotes/impl/apollo/apollo.openapi.json index 2a4043ce8..a29859425 100644 --- a/packages/core/remotes/impl/apollo/apollo.openapi.json +++ b/packages/core/remotes/impl/apollo/apollo.openapi.json @@ -9,6 +9,11 @@ "url": "https://app.apollo.io/api" } ], + "security": [ + { + "api_key": [] + } + ], "paths": { "/v1/emailer_campaigns/{id}": { "get": { @@ -424,6 +429,13 @@ } }, "components": { + "securitySchemes": { + "api_key": { + "type": "apiKey", + "name": "api_key", + "in": "query" + } + }, "schemas": { "emailer_campaign": { "type": "object", diff --git a/packages/core/remotes/impl/apollo/apollo.openapi.ts b/packages/core/remotes/impl/apollo/apollo.openapi.ts index 01d90716f..3b8fc63d6 100644 --- a/packages/core/remotes/impl/apollo/apollo.openapi.ts +++ b/packages/core/remotes/impl/apollo/apollo.openapi.ts @@ -211,6 +211,10 @@ export function outputOpenApi() { openapi: '3.1.0', info: { title: 'Apollo API', version: '0.0.0' }, servers: [{ url: 'https://app.apollo.io/api' }], + security: [{ api_key: [] }], + components: { + securitySchemes: { api_key: { type: 'apiKey', name: 'api_key', in: 'query' } }, + }, paths: { '/v1/emailer_campaigns/{id}': { get: jsonOperation('getEmailerCampaign', { diff --git a/packages/core/remotes/impl/outreach/outreach.client.ts b/packages/core/remotes/impl/outreach/outreach.client.ts index 05f09b832..8c5f1f510 100644 --- a/packages/core/remotes/impl/outreach/outreach.client.ts +++ b/packages/core/remotes/impl/outreach/outreach.client.ts @@ -1,6 +1,6 @@ +import type { OAuthClientOptions } from '@supaglue/schemas'; +import { createOpenapiOauthClient, HTTPError } from '@supaglue/schemas'; import { SGConnectionNoLongerAuthenticatedError } from '../../../errors'; -import type { OAuthClientOptions } from '../../utils/createOpenapiClient'; -import { createOpenapiOauthClient, HTTPError } from '../../utils/createOpenapiClient'; import type { paths } from './outreach.openapi.gen'; import oas from './outreach.openapi.json'; diff --git a/packages/core/remotes/impl/salesloft/salesloft.client.ts b/packages/core/remotes/impl/salesloft/salesloft.client.ts index 45c8d0fd9..b83940a1f 100644 --- a/packages/core/remotes/impl/salesloft/salesloft.client.ts +++ b/packages/core/remotes/impl/salesloft/salesloft.client.ts @@ -1,6 +1,6 @@ +import type { OAuthClientOptions } from '@supaglue/schemas'; +import { createOpenapiOauthClient } from '@supaglue/schemas'; import type { ConnectorAuthConfig } from '../../base'; -import type { OAuthClientOptions } from '../../utils/createOpenapiClient'; -import { createOpenapiOauthClient } from '../../utils/createOpenapiClient'; import type { paths } from './salesloft.openapi.gen'; import oas from './salesloft.openapi.json'; diff --git a/packages/core/remotes/utils/createOpenapiClient.ts b/packages/schemas/createOpenapiClient.ts similarity index 96% rename from packages/core/remotes/utils/createOpenapiClient.ts rename to packages/schemas/createOpenapiClient.ts index 4b202f959..f9d5246b6 100644 --- a/packages/core/remotes/utils/createOpenapiClient.ts +++ b/packages/schemas/createOpenapiClient.ts @@ -1,7 +1,6 @@ import type { FetchOptions, FetchResponse } from 'openapi-fetch'; import createClient from 'openapi-fetch'; -// @ts-expect-error Not sure we get The current file is a CommonJS module whose imports will -// produce 'require' calls error, but it's ireelevant and thus we will suppress it +// @ts-expect-error Not sure why this is needed import type { PathsWithMethod } from 'openapi-typescript-helpers'; type HTTPMethod = 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH' | 'TRACE'; diff --git a/packages/schemas/index.ts b/packages/schemas/index.ts index 2486ad419..f1134c67c 100644 --- a/packages/schemas/index.ts +++ b/packages/schemas/index.ts @@ -1 +1,2 @@ export * from './supaglue-client'; +export * from './createOpenapiClient' diff --git a/packages/schemas/package.json b/packages/schemas/package.json index 999e4ac4f..8f3b64a79 100644 --- a/packages/schemas/package.json +++ b/packages/schemas/package.json @@ -9,6 +9,7 @@ }, "devDependencies": { "openapi-typescript": "^6.7.0", + "openapi-typescript-helpers": "^0.0.4", "tsx": "^3.12.3" } } diff --git a/packages/schemas/supaglue-client.ts b/packages/schemas/supaglue-client.ts index cbaf30d93..37db9e408 100644 --- a/packages/schemas/supaglue-client.ts +++ b/packages/schemas/supaglue-client.ts @@ -1,5 +1,4 @@ -import createClient from 'openapi-fetch'; - +import { createOpenapiClient } from './createOpenapiClient'; import type { paths as actions } from './gen/v2/actions'; import type { paths as crm } from './gen/v2/crm'; import type { paths as data } from './gen/v2/data'; @@ -25,18 +24,18 @@ export function createSupaglueClient({ apiUrl = 'https://api.supaglue.io', ...op ({ baseUrl: new URL(segment, apiUrl).toString(), headers: { ['x-api-key']: options.apiKey }, - } satisfies Parameters[0]); + }) satisfies Parameters[0]; return { - actions: createClient(getOptions('actions/v2')), - crm: createClient(getOptions('crm/v2')), - data: createClient(getOptions('data/v2')), - engagement: createClient(getOptions('engagement/v2')), - enrichment: createClient(getOptions('enrichment/v2')), - marketingAutomation: createClient(getOptions('marketing-automation/v2')), - metadata: createClient(getOptions('metadata/v2')), - ticketing: createClient(getOptions('ticketing/v2')), + actions: createOpenapiClient(getOptions('actions/v2')), + crm: createOpenapiClient(getOptions('crm/v2')), + data: createOpenapiClient(getOptions('data/v2')), + engagement: createOpenapiClient(getOptions('engagement/v2')), + enrichment: createOpenapiClient(getOptions('enrichment/v2')), + marketingAutomation: createOpenapiClient(getOptions('marketing-automation/v2')), + metadata: createOpenapiClient(getOptions('metadata/v2')), + ticketing: createOpenapiClient(getOptions('ticketing/v2')), // TODO: Mgmt uses different headers, we should fix that - mgmt: createClient(getOptions('mgmt/v2')), + mgmt: createOpenapiClient(getOptions('mgmt/v2')), }; } diff --git a/yarn.lock b/yarn.lock index 7d6076af1..2e82b5ba2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6322,7 +6322,6 @@ __metadata: odata: ^1.3.2 openapi-fetch: ^0.8.1 openapi-typescript: ^6.7.1 - openapi-typescript-helpers: 0.0.4 pg: ^8.10.2 pg-connection-string: ^2.6.2 pg-copy-streams: ^6.0.6 @@ -6364,6 +6363,7 @@ __metadata: dependencies: openapi-fetch: 0.8.1 openapi-typescript: ^6.7.0 + openapi-typescript-helpers: ^0.0.4 tsx: ^3.12.3 languageName: unknown linkType: soft @@ -18546,7 +18546,7 @@ __metadata: languageName: node linkType: hard -"openapi-typescript-helpers@npm:0.0.4, openapi-typescript-helpers@npm:^0.0.4": +"openapi-typescript-helpers@npm:^0.0.4": version: 0.0.4 resolution: "openapi-typescript-helpers@npm:0.0.4" checksum: d06d62f9669db5110f32ef36a70f9f2698dd7ad03ba41968baf13e1091caaf23c4af6f8a79103cfd68f65046da4284dcc2f75e9950e9170115189b545e3030fc