Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
feat: Batch sequence steps in sequence creation and implement for Sal…
Browse files Browse the repository at this point in the history
…esloft + Outeach (#1661)

<!-- Please title your PR using conventional commits
(https://www.conventionalcommits.org/en/v1.0.0/): -->

Fixes:
https://linear.app/supaglue/issue/SUP-474/add-unified-api-endpoints-for-createupdate-sequence-sequence-steps-for

## Test Plan

Manually hitting the implemented API endpoints and checking if the
required objects have been created in Salesloft and outreach.
Translate `intervalSeconds` to salesloft's day semantic. 
[Breaking] Default to 0 for `intervalSeconds` in outreach if `date` (for absolute-dated sequences) is also not specified)
  • Loading branch information
tonyxiao authored Oct 10, 2023
1 parent 5dc00b0 commit d0eff53
Show file tree
Hide file tree
Showing 18 changed files with 561 additions and 182 deletions.
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"uuid": "^9.0.0"
},
"devDependencies": {
"@hapi/boom": "^10.0.1",
"@tsconfig/node18": "^1.0.1",
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
Expand Down
41 changes: 25 additions & 16 deletions apps/api/routes/oauth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getDependencyContainer } from '@/dependency_container';
import type { Boom } from '@hapi/boom';
import { Client as HubspotClient } from '@hubspot/api-client';
import { BadRequestError } from '@supaglue/core/errors';
import { BadRequestError, InternalServerError } from '@supaglue/core/errors';
import { getConnectorAuthConfig } from '@supaglue/core/remotes';
import type {
ConnectionCreateParamsAny,
Expand All @@ -25,6 +26,10 @@ import { Router } from 'express';
import type { AuthorizationMethod } from 'simple-oauth2';
import simpleOauth2 from 'simple-oauth2';

function isBoom<T>(err: any): err is Boom<T> {
return err.isBoom;
}

const { providerService, connectionAndSyncService, applicationService } = getDependencyContainer();

const SERVER_URL = process.env.SUPAGLUE_SERVER_URL ?? 'http://localhost:8080';
Expand Down Expand Up @@ -231,21 +236,25 @@ export default function init(app: Router): void {

// TODO: We should move all the logic that is conditional on providerName
// to their respective files
const tokenWrapper = await client.getToken(
{
code,
redirect_uri: REDIRECT_URI,
...additionalAuthParams,
},
{
headers:
providerName === 'gong'
? {
Authorization: `Basic ${Buffer.from(`${oauthClientId}:${oauthClientSecret}`).toString('base64')}`,
}
: undefined,
}
);
const tokenWrapper = await client
.getToken(
{ code, redirect_uri: REDIRECT_URI, ...additionalAuthParams },
{
headers:
providerName === 'gong'
? { Authorization: `Basic ${Buffer.from(`${oauthClientId}:${oauthClientSecret}`).toString('base64')}` }
: undefined,
}
)
.catch((err) => {
if (isBoom(err)) {
// simple-oauth2 throws boom error.
// Avoids circular reference issue when throwing a boom error directly
// Though we aren't able to get the actual json response data @see https://share.cleanshot.com/DwwWn5Cj
throw new InternalServerError(err.message);
}
throw err;
});

let instanceUrl = (tokenWrapper.token['instance_url'] as string) ?? '';

Expand Down
Loading

1 comment on commit d0eff53

@vercel
Copy link

@vercel vercel bot commented on d0eff53 Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

supaglue-docs – ./docs

docs.supaglue.com
supaglue-docs-supaglue.vercel.app
supaglue-docs-git-main-supaglue.vercel.app

Please sign in to comment.