Skip to content

Commit

Permalink
Merge branch 'master' into helpscout-support-api
Browse files Browse the repository at this point in the history
  • Loading branch information
bastienbeurier authored Jan 31, 2024
2 parents f6bb92f + 53fc0d9 commit bfd9700
Show file tree
Hide file tree
Showing 32 changed files with 166 additions and 256 deletions.
1 change: 1 addition & 0 deletions docs-v2/api-reference/sync/update-connection-frequency.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ title: 'Update sync connection frequency'
openapi: 'PUT /sync/update-connection-frequency'
---

Update the frequency of a specific sync and connection
4 changes: 3 additions & 1 deletion docs-v2/integrations/all/github.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: GitHub
sidebarTitle: GitHub
---

API configuration: [`github`](https://nango.dev/providers.yaml), [`github-app`](https://nango.dev/providers.yaml)
API configuration: [`github`](https://nango.dev/providers.yaml), [`github-app`](https://nango.dev/providers.yaml), [`github-app-oauth`](https://nango.dev/providers.yaml)

## Features

Expand Down Expand Up @@ -36,6 +36,8 @@ API configuration: [`github`](https://nango.dev/providers.yaml), [`github-app`](
- The App Public Link is the URL to your Github App public page (e.g. https://github.com/apps/nango-github-app)
- The App Private Key needs to be generated in your GitHub App settings and starts with `-----BEGIN RSA PRIVATE KEY-----` (not to be confused with the Client Secrets)
- The Setup URL (displayed on your Nango integration page) needs to be added to your GitHub App configuration (not to be confused with the Callback URL that can stay empty)
- There are certain API methods that only work with an OAuth App that will not work with an App. Please check the Github documentation and look for a "Works with Github Apps" header under the endpoint.
- The `github-app-oauth` is a combination of a Github App and OAuth and should be used when a Github App would need approval to be installed into an organization.
- Nango supports initiating a connection with a GitHub App using the [Frontend SDK](https://docs.nango.dev/sdks/frontend#collecting-and-storing-end-user-credentials), but not directly from the [GitHub Marketplace](https://github.com/marketplace). Therefore, you should encourage users to install your GitHub App from your product, rather than from the GitHub Marketplace directly. This is a limitation we plan to fix in the future.

<Note>Add Getting Started links and Gotchas by [editing this page](https://github.com/nangohq/nango/tree/master/docs-v2/integrations/all/github.mdx)</Note>
2 changes: 1 addition & 1 deletion docs-v2/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ You can get Nango up and running in just 3 minutes with the [Quickstart 🚀](/q
For more details:
* Learn [how to integrate Nango](/guides/integrate)
* Join & ask any question on the [community](https://nango.dev/slack)
* Book a [demo](https://nango.dev/call)
* Book a [demo](https://calendly.com/rguldener/30min)
1 change: 1 addition & 0 deletions docs-v2/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"integrations/all/gitlab",
"integrations/all/gong",
"integrations/all/google",
"integrations/all/google-ads",
"integrations/all/google-calendar",
"integrations/all/google-mail",
"integrations/all/google-sheet",
Expand Down
10 changes: 5 additions & 5 deletions docs-v2/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,8 @@ paths:
type: string

/sync/update-connection-frequency:
get:
description: Update a sync's connection frequency or revert to the default frequency
put:
description: Override a sync's default frequency for a specific connection, or revert to the default frequency.
requestBody:
required: true
content:
Expand All @@ -943,7 +943,7 @@ paths:
required:
- provider_config_key
- connection_id
- sync
- sync_name
- frequency
properties:
provider_config_key:
Expand All @@ -952,13 +952,13 @@ paths:
connection_id:
type: string
description: The ID of the connection
sync:
sync_name:
type: string
description: The name of the sync you want to update
frequency:
type: string
nullable: true
description: The frequency you want to set. Set null to revert to the default frequency
description: "The frequency you want to set (ex: 'every hour'). Set null to revert to the default frequency"
responses:
'200':
description: Successfully updated the frequency
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion packages/cli/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const generate = async (debug = false, inParentDirectory = false) => {
const syncTemplateContents = fs.readFileSync(path.resolve(__dirname, './templates/sync.ejs'), 'utf8');
const actionTemplateContents = fs.readFileSync(path.resolve(__dirname, './templates/action.ejs'), 'utf8');
const githubExampleTemplateContents = fs.readFileSync(path.resolve(__dirname, './templates/github.sync.ejs'), 'utf8');
const postConnectionTemplateContents = fs.readFileSync(path.resolve(__dirname, './templates/post-connection.ejs'), 'utf8');

const configContents = fs.readFileSync(`${dirPrefix}/${nangoConfigFile}`, 'utf8');
const configData: NangoConfig = yaml.load(configContents) as unknown as NangoConfig;
Expand Down Expand Up @@ -74,7 +75,27 @@ export const generate = async (debug = false, inParentDirectory = false) => {
const allSyncNames: Record<string, boolean> = {};

for (const standardConfig of config) {
const { syncs, actions } = standardConfig;
const { syncs, actions, postConnectionScripts } = standardConfig;

if (postConnectionScripts) {
for (const name of postConnectionScripts) {
const rendered = ejs.render(postConnectionTemplateContents, {
interfaceFileName: TYPES_FILE_NAME.replace('.ts', '')
});
const stripped = rendered.replace(/^\s+/, '');

if (!fs.existsSync(`${dirPrefix}/${name}.ts`)) {
fs.writeFileSync(`${dirPrefix}/${name}.ts`, stripped);
if (debug) {
printDebug(`Created ${name}.ts file`);
}
} else {
if (debug) {
printDebug(`${name}.ts file already exists, so will not overwrite it.`);
}
}
}
}

for (const flow of [...syncs, ...actions]) {
const { name, type, returns: models, input } = flow;
Expand Down
1 change: 1 addition & 0 deletions packages/cli/lib/fixtures/nango-yaml/v2/valid/object.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
{
"providerConfigKey": "demo-github-integration",
"postConnectionScripts": [],
"syncs": [
{
"name": "github-issue-example",
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/lib/nango.yaml.schema.v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
"additionalProperties": {
"type": "object",
"properties": {
"post-connection-scripts": {
"type": "array",
"items": {
"type": "string"
},
"errorMessage": {
"_": "nango yaml schema validation error: post-connection-scripts must be an array of strings."
}
},
"syncs": {
"errorMessage": {
"_": " "
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/lib/templates/post-connection.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { NangoSync } from './<%= interfaceFileName %>';

export default async function postConnection(nango: NangoSync): Promise<void> {
// post connection logic goes here
}
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nango",
"version": "0.37.8",
"version": "0.37.9",
"description": "Nango's CLI tool.",
"type": "module",
"main": "dist/index.js",
Expand All @@ -26,7 +26,7 @@
"dependencies": {
"@babel/traverse": "^7.22.5",
"@inquirer/prompts": "^2.3.0",
"@nangohq/shared": "^0.37.8",
"@nangohq/shared": "^0.37.9",
"@vercel/ncc": "^0.36.1",
"ajv": "^8.12.0",
"ajv-errors": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nangohq/frontend",
"version": "0.37.8",
"version": "0.37.9",
"description": "Nango's frontend library for OAuth handling.",
"type": "module",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/jobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"@nangohq/nango-runner": "^1.0.0",
"@nangohq/shared": "^0.37.8",
"@nangohq/shared": "^0.37.9",
"@octokit/plugin-retry": "^6.0.0",
"@octokit/plugin-throttling": "^7.0.0",
"@octokit/rest": "^20.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/node-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nangohq/node",
"version": "0.37.8",
"version": "0.37.9",
"description": "Nango's Node client.",
"type": "module",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"license": "SEE LICENSE IN LICENSE FILE IN GIT REPOSITORY",
"dependencies": {
"@nangohq/shared": "^0.37.8",
"@nangohq/shared": "^0.37.9",
"@trpc/client": "^10.44.0",
"@trpc/server": "^10.44.0",
"api": "^6.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"@hapi/boom": "^10.0.1",
"@nangohq/shared": "^0.37.8",
"@nangohq/shared": "^0.37.9",
"@sentry/node": "^7.37.2",
"@temporalio/client": "^1.7.4",
"axios": "^1.3.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { RecentlyCreatedConnection, Connection, ConnectionConfig } from '..
import { LogLevel, LogActionEnum } from '../../../models/Activity.js';
import { createActivityLogAndLogMessage } from '../../../services/activity/activity.service.js';
import type { HTTP_VERB } from '../../../models/Generic.js';
import type { UserProvidedProxyConfiguration } from '../../../models/Proxy.js';
import proxyService from '../../../services/proxy.service.js';
import connectionService from '../../../services/connection.service.js';
import environmentService from '../../../services/environment.service.js';
Expand All @@ -19,8 +20,8 @@ type PostConnectionHandlersMap = { [key: string]: PostConnectionHandler };
const handlers: PostConnectionHandlersMap = postConnectionHandlers as unknown as PostConnectionHandlersMap;

export interface InternalNango {
proxy: ({ method, endpoint, data }: { method?: HTTP_VERB; endpoint: string; data?: unknown }) => Promise<AxiosResponse>;
getConnection: () => Promise<Connection>;
proxy: ({ method, endpoint, data }: UserProvidedProxyConfiguration) => Promise<AxiosResponse>;
updateConnectionConfig: (config: ConnectionConfig) => Promise<ConnectionConfig>;
}

Expand Down Expand Up @@ -56,18 +57,18 @@ async function execute(createdConnection: RecentlyCreatedConnection, provider: s
};

const internalNango: InternalNango = {
proxy: ({ method, endpoint, data }: { endpoint: string; method?: HTTP_VERB; data?: unknown }) => {
getConnection: async () => {
const { response: connection } = await connectionService.getConnection(connection_id, provider_config_key, environment_id);

return connection as Connection;
},
proxy: ({ method, endpoint, data }: UserProvidedProxyConfiguration) => {
const finalExternalConfig = { ...externalConfig, method: method || externalConfig.method, endpoint };
if (data) {
finalExternalConfig.data = data;
}
return proxyService.routeOrConfigure(finalExternalConfig, internalConfig) as Promise<AxiosResponse>;
},
getConnection: async () => {
const { response: connection } = await connectionService.getConnection(connection_id, provider_config_key, environment_id);

return connection as Connection;
},
updateConnectionConfig: (connectionConfig: ConnectionConfig) => {
return connectionService.updateConnectionConfig(connection as unknown as Connection, connectionConfig);
}
Expand Down Expand Up @@ -95,7 +96,7 @@ async function execute(createdConnection: RecentlyCreatedConnection, provider: s
end: Date.now(),
timestamp: Date.now(),
connection_id: connection_id,
provider: '',
provider,
provider_config_key: provider_config_key,
environment_id
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as hubspotPostConnection } from './hubspot-post-connection.js';
export { default as jiraPostConnection } from './jira-post-connection.js';
export { default as githubappoauthPostConnection } from './github-app-oauth-post-connection.js';
export { default as salesforcePostConnection } from './salesforce-post-connection.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { InternalNango as Nango } from './connection.manager.js';

export default async function execute(nango: Nango) {
// TODO implementation later
console.log(nango);
}
1 change: 1 addition & 0 deletions packages/shared/lib/integrations/scripts/webhook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { default as jiraWebhook } from './jira-webhook-routing.js';
export { default as slackWebhook } from './slack-webhook-routing.js';
export { default as githubappWebhook } from './github-app-webhook-routing.js';
export { default as githubappoauthWebhook } from './github-app-oauth-webhook-routing.js';
export { default as salesforceWebhook } from './salesforce-webhook-routing.js';
24 changes: 19 additions & 5 deletions packages/shared/lib/integrations/scripts/webhook/internal-nango.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import get from 'lodash-es/get.js';
import environmentService from '../../../services/environment.service.js';
import type { Connection } from './../../../models/Connection.js';
import type { Config as ProviderConfig } from './../../../models/Provider.js';
import SyncClient from '../../../clients/sync.client.js';
import type { SyncConfig } from './../../../models/Sync.js';
Expand Down Expand Up @@ -50,11 +51,24 @@ export const internalNango: InternalNango = {
return;
}

const connections = await connectionService.findConnectionsByConnectionConfigValue(
propName || connectionIdentifier,
get(body, connectionIdentifier),
integration.environment_id
);
let connections: Connection[] | null = null;
if (propName === 'connectionId') {
const { success, response: connection } = await connectionService.getConnection(
get(body, connectionIdentifier),
integration.unique_key,
integration.environment_id
);

if (success && connection) {
connections = [connection];
}
} else {
connections = await connectionService.findConnectionsByConnectionConfigValue(
propName || connectionIdentifier,
get(body, connectionIdentifier),
integration.environment_id
);
}

if (!connections || connections.length === 0) {
await metricsManager.capture(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { InternalNango as Nango } from './internal-nango.js';
import type { Config as ProviderConfig } from '../../../models/Provider.js';

export default async function route(nango: Nango, integration: ProviderConfig, _headers: Record<string, any>, body: any) {
await nango.executeScriptForWebhooks(integration, body, 'nango.eventType', 'nango.connectionId', 'connectionId');
}
2 changes: 2 additions & 0 deletions packages/shared/lib/models/NangoConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface NangoV2IntegrationContents {
provider?: string;
syncs?: NangoIntegrationDataV2[];
actions?: NangoIntegrationDataV2[];
'post-connection-scripts'?: string[];
}

export interface NangoV2Integration {
Expand Down Expand Up @@ -129,4 +130,5 @@ export interface StandardNangoConfig {
provider?: string;
syncs: NangoSyncConfig[];
actions: NangoSyncConfig[];
postConnectionScripts?: string[];
}
Loading

0 comments on commit bfd9700

Please sign in to comment.