Skip to content

Commit

Permalink
enabling postconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
pellicceama committed Nov 11, 2024
1 parent 5bd38e8 commit 0e944a7
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions connectors/connector-hubspot/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {initHubspotSDK, type HubspotSDK} from '@opensdks/sdk-hubspot'
import type {ConnectorServer} from '@openint/cdk'
import {initNangoSDK, type ConnectorServer} from '@openint/cdk'
import {Rx, rxjs} from '@openint/util'
import {HUBSPOT_ENTITIES, hubspotHelpers, type hubspotSchemas} from './def'

Expand Down Expand Up @@ -40,11 +40,44 @@ export const hubspotServer = {
},
// TODO enable this once we look into the data model of connectOutput
// and map most appropriate response for hubspot
// postConnect: (connectOutput) => ({
// resourceExternalId: connectOutput.resourceExternalId,
// settings: connectOutput.settings,
// triggerDefaultSync: true,
// }),
postConnect: async (connectOutput, config, context) => {
console.log('hubspot postConnect input:', {
connectOutput,
config,
context,
})
// TODO: pass this context in via postConnect?
const nango = initNangoSDK({
headers: {authorization: `Bearer ${process.env['NANGO_SECRET_KEY']}`},
})
const nangoConnection = await nango
.GET('/connection/{connectionId}', {
params: {
path: {connectionId: connectOutput.connectionId},
query: {
provider_config_key: connectOutput.providerConfigKey,
},
},
})
.then((r) => r.data)

console.log('nangoConnection', JSON.stringify(nangoConnection, null, 2))
const _instance = initHubspotSDK({
headers: {
authorization: `Bearer ${nangoConnection.credentials.access_token}`,

Check failure on line 67 in connectors/connector-hubspot/server.ts

View workflow job for this annotation

GitHub Actions / Run type checks, lint, and tests

Property 'credentials' does not exist on type 'never'.

Check failure on line 67 in connectors/connector-hubspot/server.ts

View workflow job for this annotation

GitHub Actions / Run type checks, lint, and tests

Property 'credentials' does not exist on type 'never'.
},
})
const accountInfo = await _instance.crm_objects
.request('GET', '/integrations/v1/me', {})
.then((r) => r.data)
return {
resourceExternalId: accountInfo.portalId,

Check failure on line 74 in connectors/connector-hubspot/server.ts

View workflow job for this annotation

GitHub Actions / Run type checks, lint, and tests

'accountInfo' is of type 'unknown'.

Check failure on line 74 in connectors/connector-hubspot/server.ts

View workflow job for this annotation

GitHub Actions / Run type checks, lint, and tests

'accountInfo' is of type 'unknown'.
settings: {
oauth: nangoConnection,
},
triggerDefaultSync: true,
}
},
// @ts-expect-error QQ why is typing failing here?
sourceSync: ({instance: hubspot, streams, state}) => {
async function* iterateEntities() {
Expand Down

0 comments on commit 0e944a7

Please sign in to comment.