-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(post-connection-scripts): [nan-1901] add post connection scripts (…
…#2856) ## Describe your changes Adds post connection scripts for gusto, docusign, calendly ## Issue ticket number and link NAN-1901 ## Checklist before requesting a review (skip if just adding/editing APIs & templates) - [ ] I added tests, otherwise the reason is: - [ ] I added observability, otherwise the reason is: - [ ] I added analytics, otherwise the reason is:
- Loading branch information
1 parent
c3a7e64
commit e5d9a09
Showing
9 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/server/lib/hooks/connection/calendly-post-connection.ts
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,25 @@ | ||
import type { InternalNango as Nango } from './post-connection.js'; | ||
import type { CalendlyUser } from '../response-types/calendly.js'; | ||
import { isAxiosError } from 'axios'; | ||
|
||
export default async function execute(nango: Nango) { | ||
const connection = await nango.getConnection(); | ||
|
||
const response = await nango.proxy<CalendlyUser>({ | ||
endpoint: '/users/me', | ||
connectionId: connection.connection_id, | ||
providerConfigKey: connection.provider_config_key | ||
}); | ||
|
||
if (isAxiosError(response)) { | ||
return; | ||
} | ||
|
||
const { data } = response; | ||
|
||
const { current_organization } = data.resource; | ||
|
||
const organizationId = current_organization.split('/').pop(); | ||
|
||
await nango.updateConnectionConfig({ organizationId }); | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/server/lib/hooks/connection/docusign-post-connection.ts
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,35 @@ | ||
import type { InternalNango as Nango } from './post-connection.js'; | ||
import type { UserInfoResponse, AccountInfo } from '../response-types/docusign.js'; | ||
import { isAxiosError } from 'axios'; | ||
|
||
export default async function execute(nango: Nango) { | ||
const connection = await nango.getConnection(); | ||
|
||
const rootUrl = connection.provider_config_key.includes('sandbox') ? 'account-d.docusign.com' : 'account.docusign.com'; | ||
|
||
const response = await nango.proxy<UserInfoResponse>({ | ||
baseUrlOverride: `https://${rootUrl}`, | ||
endpoint: '/oauth/userinfo', | ||
connectionId: connection.connection_id, | ||
providerConfigKey: connection.provider_config_key | ||
}); | ||
|
||
if (isAxiosError(response)) { | ||
return; | ||
} | ||
|
||
if (response.data.accounts.length <= 0) { | ||
return; | ||
} | ||
|
||
const defaultAccount = response.data.accounts.find((account: AccountInfo) => account.is_default); | ||
|
||
if (!defaultAccount) { | ||
return; | ||
} | ||
|
||
await nango.updateConnectionConfig({ | ||
baseUri: defaultAccount.base_uri, | ||
accountId: defaultAccount.account_id | ||
}); | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/server/lib/hooks/connection/gusto-post-connection.ts
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,28 @@ | ||
import type { InternalNango as Nango } from './post-connection.js'; | ||
import type { GustoTokenInfoResponse } from '../response-types/gusto.js'; | ||
import { isAxiosError } from 'axios'; | ||
|
||
export default async function execute(nango: Nango) { | ||
const connection = await nango.getConnection(); | ||
const rootUrl = connection.provider_config_key.includes('sandbox') ? 'api.gusto-demo.com' : 'api.gusto.com'; | ||
|
||
const response = await nango.proxy<GustoTokenInfoResponse>({ | ||
baseUrlOverride: `https://${rootUrl}`, | ||
endpoint: '/v1/token_info', | ||
connectionId: connection.connection_id, | ||
providerConfigKey: connection.provider_config_key | ||
}); | ||
|
||
if (isAxiosError(response)) { | ||
return; | ||
} | ||
|
||
const { data } = response; | ||
|
||
const { resource } = data; | ||
|
||
if (resource.type === 'Company') { | ||
const { uuid } = resource; | ||
await nango.updateConnectionConfig({ companyUuid: uuid }); | ||
} | ||
} |
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
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,16 @@ | ||
export interface CalendlyUser { | ||
resource: { | ||
uri: string; | ||
name: string; | ||
slug: string; | ||
email: string; | ||
scheduling_url: string; | ||
timezone: string; | ||
avatar_url: string; | ||
created_at: string; | ||
updated_at: string; | ||
current_organization: string; | ||
resource_type: string; | ||
locale: string; | ||
}; | ||
} |
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 @@ | ||
export interface UserInfoResponse { | ||
sub: string; | ||
name: string; | ||
given_name: string; | ||
family_name: string; | ||
created: string; | ||
email: string; | ||
accounts: AccountInfo[]; | ||
} | ||
|
||
export interface AccountInfo { | ||
account_id: string; | ||
is_default: boolean; | ||
account_name: string; | ||
base_uri: string; | ||
organization: OrganizationInfo; | ||
} | ||
|
||
interface OrganizationInfo { | ||
organization_id: string; | ||
links: OrgLinkInfo[]; | ||
} | ||
|
||
interface OrgLinkInfo { | ||
rel: string; | ||
href: string; | ||
} |
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,11 @@ | ||
export interface GustoTokenInfoResponse { | ||
scope: string; | ||
resource: { | ||
type: string; | ||
uuid: string; | ||
}; | ||
resource_owner: { | ||
type: string; | ||
uuid: string; | ||
}; | ||
} |
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