Skip to content

Commit

Permalink
feat(integrations): add harvest connect ui docs and a post connection…
Browse files Browse the repository at this point in the history
… script (#3148)

## Describe the problem and your solution

- Added harvest `connect-ui` docs
- Added a post connection script to update the `connectionConfig` with a
`emailConnection` value this way if the `appDetails` is not provided
nango will automatically use this value to build proxies which is
crucial. The provider recommends a unique name and means of
communication, hence the pattern `connection_id.email` in the
`postConnection` script.
- 

<!-- Issue ticket number and link (if applicable) -->

## Testing instructions

- Create a new harvest connection, the `emailConnection` is
automatically populated.

---------

Co-authored-by: Hassan Wari <hassanwari@Hassans-MacBook-Pro.local>
  • Loading branch information
hassan254-prog and Hassan Wari authored Dec 12, 2024
1 parent 1fba306 commit ef33847
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs-v2/integrations/all/harvest.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ API configuration: [`harvest`](https://nango.dev/providers.yaml)
## Getting started

- [OAuth-related docs](https://help.getharvest.com/api-v2/authentication-api/authentication/authentication/#oauth2-application)
- [Register an Application](https://id.getharvest.com/sessions/new?go_back=%2Fdevelopers)
- [Register an Application](https://id.getharvest.com/oauth2/clients/new)
- [Scopes](https://help.getharvest.com/api-v2/authentication-api/authentication/authentication/#scopes-and-account-access)
- [Harvest REST API docs](https://help.getharvest.com/api-v2)

Expand Down
9 changes: 8 additions & 1 deletion packages/shared/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,14 @@ export function mapProxyBaseUrlInterpolationFormat(baseUrl: string | undefined):

export function interpolateIfNeeded(str: string, replacers: Record<string, any>) {
if (str.includes('${')) {
return interpolateStringFromObject(str, replacers);
if (str.includes('||')) {
const parts = str.split('||');
const firstPart = parts[0] ? interpolateStringFromObject(parts[0].trim(), replacers) : undefined;
const secondPart = parts[1] ? interpolateStringFromObject(parts[1].trim(), replacers) : undefined;
return (firstPart || secondPart) as string;
} else {
return interpolateStringFromObject(str, replacers);
}
} else {
return str;
}
Expand Down
34 changes: 34 additions & 0 deletions packages/shared/lib/utils/utils.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,37 @@ describe('encodeParameters Function Tests', () => {
expect(utils.encodeParameters(params)).toEqual(expected);
});
});

describe('interpolateIfNeeded', () => {
it('should interpolate both parts when "||" is present', () => {
const input = '${connectionConfig.appDetails} || ${connectionConfig.userEmail}';
const result = utils.interpolateIfNeeded(input, {
connectionConfig: {
appDetails: 'MyAppDetails',
userEmail: 'unknown@example.com'
}
});
expect(result).toBe('MyAppDetails');
});

it('should use the fallback if the first part is empty', () => {
const input = '${connectionConfig.appDetails} || ${connectionConfig.userEmail}';
const result = utils.interpolateIfNeeded(input, {
connectionConfig: {
appDetails: '',
userEmail: 'fallback@example.com'
}
});
expect(result).toBe('fallback@example.com');
});

it('should return only the first part if "||" is not present', () => {
const input = '${connectionConfig.appDetails}';
const result = utils.interpolateIfNeeded(input, {
connectionConfig: {
appDetails: 'MyAppDetails'
}
});
expect(result).toBe('MyAppDetails');
});
});
3 changes: 2 additions & 1 deletion packages/shared/providers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3364,7 +3364,7 @@ harvest:
grant_type: refresh_token
proxy:
headers:
user-agent: ${connectionConfig.appDetails}
user-agent: ${connectionConfig.appDetails} || App (support@nango.dev)
retry:
after: 'retry-after'
base_url: https://api.harvestapp.com
Expand All @@ -3374,6 +3374,7 @@ harvest:
type: string
title: App Details
description: The details of your app
automated: true

health-gorilla:
display_name: Health Gorilla
Expand Down

0 comments on commit ef33847

Please sign in to comment.