-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hubspot): add hubspot integrations (#49)
## Describe your changes - Add Integrations for hubspot ## Actions - create-contact - create-company - create-deal - create-task - create-note - update-contact - update-company - update-deal - update-task - delete-contact - delete-company - delete-deal - delete-task ## Syncs - contacts - companies - deals - tasks ## Issue ticket number and link ## Checklist before requesting a review (skip if just adding/editing APIs & templates) - [x] I added tests, otherwise the reason is: - [x] External API requests have `retries` - [x] Pagination is used where appropriate - [x] The built in `nango.paginate` call is used instead of a `while (true)` loop - [x] Third party requests are NOT parallelized (this can cause issues with rate limits) - [ ] If a sync requires metadata the `nango.yaml` has `auto_start: false` - [x] If the sync is a `full` sync then `track_deletes: true` is set --------- Co-authored-by: Khaliq <khaliqgant@gmail.com>
- Loading branch information
1 parent
e0a44f0
commit d4501e4
Showing
118 changed files
with
5,183 additions
and
10,164 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,16 @@ | ||
import type { NangoAction, Company, CreateCompany } from '../../models'; | ||
import type { HubspotCompanyResponse } from '../types'; | ||
import { createCompanySchema } from '../schema.zod.js'; | ||
import type { NangoAction, ProxyConfiguration, CreateUpdateCompanyOutput, CreateCompanyInput } from '../../models'; | ||
import { createUpdateCompany, toHubspotCompany } from '../mappers/toCompany.js'; | ||
|
||
/** | ||
* Executes an action to create a company based on the provided input. | ||
* It validates the input against the defined schema, logs any validation errors, | ||
* and then sends a POST request to create a company if the input is valid. | ||
* @param nango - An instance of NangoAction used for logging and making API requests. | ||
* @param input - The input data required to create a company. | ||
* @returns A promise that resolves to the response from the API after creating the company. | ||
* @throws An ActionError if the input validation fails. | ||
*/ | ||
export default async function runAction(nango: NangoAction, input: CreateCompany): Promise<Company> { | ||
const parsedInput = createCompanySchema.safeParse(input); | ||
|
||
if (!parsedInput.success) { | ||
for (const error of parsedInput.error.errors) { | ||
await nango.log(`Invalid input provided to create a company: ${error.message} at path ${error.path.join('.')}`, { level: 'error' }); | ||
} | ||
throw new nango.ActionError({ | ||
message: 'Invalid input provided to create a company' | ||
}); | ||
} | ||
|
||
for (const key in parsedInput.data.properties) { | ||
const lowerKey = key.toLowerCase(); | ||
if (lowerKey !== key) { | ||
parsedInput.data.properties[lowerKey] = parsedInput.data.properties[key]; | ||
delete parsedInput.data.properties[key]; | ||
} | ||
} | ||
export default async function runAction(nango: NangoAction, input: CreateCompanyInput): Promise<CreateUpdateCompanyOutput> { | ||
const hubSpotCompany = toHubspotCompany(input); | ||
const config: ProxyConfiguration = { | ||
// https://developers.hubspot.com/docs/api/crm/companies#create-companies | ||
endpoint: 'crm/v3/objects/companies', | ||
data: hubSpotCompany, | ||
retries: 10 | ||
}; | ||
|
||
const response = await nango.post<HubspotCompanyResponse>({ | ||
endpoint: `/crm/v3/objects/companies`, | ||
retries: 10, | ||
data: parsedInput.data | ||
}); | ||
const response = await nango.post(config); | ||
|
||
return { | ||
id: response.data.id, | ||
createdAt: response.data.createdAt, | ||
updatedAt: response.data.updatedAt, | ||
name: response.data.properties.name, | ||
domain: response.data.properties.domain, | ||
archived: response.data.archived | ||
}; | ||
return createUpdateCompany(response.data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import type { NangoAction, ProxyConfiguration, CreateDeal, CreatedDeal } from '../../models'; | ||
import type { NangoAction, ProxyConfiguration, CreateDealInput, CreateUpdateDealOutput } from '../../models'; | ||
import { createUpdateDeal, toHubspotDeal } from '../mappers/toDeal.js'; | ||
|
||
export default async function runAction(nango: NangoAction, input: CreateDeal): Promise<CreatedDeal> { | ||
export default async function runAction(nango: NangoAction, input: CreateDealInput): Promise<CreateUpdateDealOutput> { | ||
const hubSpotDeal = toHubspotDeal(input); | ||
const config: ProxyConfiguration = { | ||
// https://developers.hubspot.com/docs/api/crm/deals | ||
endpoint: 'crm/v3/objects/deals', | ||
data: input, | ||
data: hubSpotDeal, | ||
retries: 10 | ||
}; | ||
|
||
// https://developers.hubspot.com/docs/api/crm/deals#create-deals | ||
const response = await nango.post(config); | ||
|
||
return response.data; | ||
return createUpdateDeal(response.data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { NangoAction, ProxyConfiguration, Note } from '../../models'; | ||
import { toNote, toHubspotNote } from '../mappers/toNote.js'; | ||
|
||
export default async function runAction(nango: NangoAction, input: Note): Promise<Note> { | ||
const hubSpotNote = toHubspotNote(input); | ||
const config: ProxyConfiguration = { | ||
// https://developers.hubspot.com/docs/api/crm/notes | ||
endpoint: 'crm/v3/objects/notes', | ||
data: hubSpotNote, | ||
retries: 10 | ||
}; | ||
const response = await nango.post(config); | ||
|
||
return toNote(response.data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { CreateTaskInput, NangoAction, ProxyConfiguration, CreateUpdateTaskOutput } from '../../models'; | ||
import { createUpdateTask, toHubspotTask } from '../mappers/toTask.js'; | ||
import { CreateTaskInputSchema } from '../schema.js'; | ||
|
||
export default async function runAction(nango: NangoAction, input: CreateTaskInput): Promise<CreateUpdateTaskOutput> { | ||
const parsedInput = CreateTaskInputSchema.safeParse(input); | ||
|
||
if (!parsedInput.success) { | ||
for (const error of parsedInput.error.errors) { | ||
await nango.log(`Invalid input provided to create a task: ${error.message} at path ${error.path.join('.')}`, { level: 'error' }); | ||
} | ||
throw new nango.ActionError({ | ||
message: 'Invalid input provided to create a task' | ||
}); | ||
} | ||
|
||
const hubSpotNote = toHubspotTask(parsedInput.data); | ||
const config: ProxyConfiguration = { | ||
// https://developers.hubspot.com/docs/api/crm/tasks | ||
endpoint: 'crm/v3/objects/tasks', | ||
data: hubSpotNote, | ||
retries: 10 | ||
}; | ||
const response = await nango.post(config); | ||
|
||
return createUpdateTask(response.data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { NangoAction, ProxyConfiguration, Id, SuccessResponse } from '../../models'; | ||
|
||
export default async function runAction(nango: NangoAction, input: Id): Promise<SuccessResponse> { | ||
const config: ProxyConfiguration = { | ||
// https://developers.hubspot.com/docs/api/crm/companies#delete-companies | ||
endpoint: `/crm/v3/objects/companies/${input.id}`, | ||
retries: 10 | ||
}; | ||
|
||
await nango.delete(config); | ||
|
||
return { | ||
success: true | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { NangoAction, ProxyConfiguration, Id, SuccessResponse } from '../../models'; | ||
|
||
export default async function runAction(nango: NangoAction, input: Id): Promise<SuccessResponse> { | ||
const config: ProxyConfiguration = { | ||
// https://developers.hubspot.com/docs/api/crm/contacts#delete-contacts | ||
endpoint: `/crm/v3/objects/contacts/${input.id}`, | ||
retries: 10 | ||
}; | ||
await nango.delete(config); | ||
|
||
return { | ||
success: true | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { NangoAction, ProxyConfiguration, Id, SuccessResponse } from '../../models'; | ||
|
||
export default async function runAction(nango: NangoAction, input: Id): Promise<SuccessResponse> { | ||
const config: ProxyConfiguration = { | ||
// https://developers.hubspot.com/docs/api/crm/deals#delete-deals | ||
endpoint: `/crm/v3/objects/deals/${input.id}`, | ||
retries: 10 | ||
}; | ||
await nango.delete(config); | ||
|
||
return { | ||
success: true | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { NangoAction, ProxyConfiguration, Id, SuccessResponse } from '../../models'; | ||
|
||
export default async function runAction(nango: NangoAction, input: Id): Promise<SuccessResponse> { | ||
const config: ProxyConfiguration = { | ||
// https://developers.hubspot.com/docs/api/crm/tasks | ||
endpoint: `/crm/v3/objects/tasks/${input.id}`, | ||
retries: 10 | ||
}; | ||
await nango.delete(config); | ||
|
||
return { | ||
success: true | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.