Skip to content

Commit

Permalink
feat:Add integration with Close CRM
Browse files Browse the repository at this point in the history
  • Loading branch information
rajesh-jonnalagadda committed Jun 6, 2024
1 parent 04ce302 commit f88d7e4
Show file tree
Hide file tree
Showing 46 changed files with 2,780 additions and 33 deletions.
1 change: 1 addition & 0 deletions packages/api/scripts/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ CREATE TABLE project_connectors
crm_zendesk boolean NOT NULL,
crm_pipedrive boolean NOT NULL,
crm_attio boolean NOT NULL,
crm_close boolean NOT NULL,
tcg_zendesk boolean NOT NULL,
tcg_gorgias boolean NOT NULL,
tcg_front boolean NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ZendeskConnectionService } from './services/zendesk/zendesk.service';
import { PipedriveConnectionService } from './services/pipedrive/pipedrive.service';
import { AttioConnectionService } from './services/attio/attio.service';
import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service';
import { CloseConnectionService } from './services/close/close.service';

@Module({
imports: [WebhookModule],
Expand All @@ -31,6 +32,7 @@ import { ConnectionsStrategiesService } from '@@core/connections-strategies/conn
ZohoConnectionService,
ZendeskConnectionService,
PipedriveConnectionService,
CloseConnectionService,
],
exports: [CrmConnectionsService],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class CloseConnectionService implements ICrmConnectionService {
data: {
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
account_url: CONNECTORS_METADATA['crm']['close'].urls.apiUrl,
account_url: CONNECTORS_METADATA['crm']['close']?.urls?.apiUrl,
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_in) * 1000,
),
Expand Down Expand Up @@ -153,10 +153,10 @@ export class CloseConnectionService implements ICrmConnectionService {
)) as OAuth2AuthData;

const formData = new URLSearchParams({
grant_type: 'refresh_token',
refresh_token: this.cryptoService.decrypt(refreshToken),
client_id: CREDENTIALS.CLIENT_ID,
client_secret: CREDENTIALS.CLIENT_SECRET,
grant_type: 'refresh_token',
});
const res = await axios.post(
'https://api.close.com/oauth2/token',
Expand All @@ -168,18 +168,21 @@ export class CloseConnectionService implements ICrmConnectionService {
},
);
const data: CloseOAuthResponse = res.data;
await this.prisma.connections.update({
where: {
id_connection: connectionId,
},
data: {
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_in) * 1000,
),
},
});
if (res?.data?.access_token) {
//only update when it is successful
await this.prisma.connections.update({
where: {
id_connection: connectionId,
},
data: {
access_token: this.cryptoService.encrypt(data?.access_token),
refresh_token: this.cryptoService.encrypt(data?.refresh_token),
expiration_timestamp: new Date(
new Date().getTime() + Number(data?.expires_in) * 1000,
),
},
});
}
this.logger.log('OAuth credentials updated : close ');
} catch (error) {
handleServiceError(error, this.logger, 'close', Action.oauthRefresh);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface TypeCustom {
tcg_front: boolean;
tcg_jira: boolean;
tcg_gitlab: boolean;
crm_close: boolean;
}
@ApiTags('project-connectors')
@Controller('project-connectors')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class ProjectConnectorsService {
tcg_front: data.tcg_front,
tcg_jira: data.tcg_jira,
tcg_gitlab: data.tcg_gitlab,
crm_close: data.crm_close,
};

const res = await this.prisma.project_connectors.create({
Expand Down
64 changes: 50 additions & 14 deletions packages/api/src/@core/utils/types/original/original.crm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HubspotCompanyOutput } from '@crm/company/services/hubspot/types';
import { PipedriveCompanyOutput } from '@crm/company/services/pipedrive/types';
import { ZendeskCompanyOutput } from '@crm/company/services/zendesk/types';
import { ZohoCompanyOutput } from '@crm/company/services/zoho/types';
import { CloseCompanyOutput } from '@crm/company/services/close/types';
import {
AttioContactInput,
AttioContactOutput,
Expand All @@ -19,10 +20,15 @@ import {
ZohoContactInput,
ZohoContactOutput,
} from '@crm/contact/services/zoho/types';
import {
CloseContactInput,
CloseContactOutput,
} from '@crm/contact/services/close/types';
import { HubspotDealOutput } from '@crm/deal/services/hubspot/types';
import { PipedriveDealOutput } from '@crm/deal/services/pipedrive/types';
import { ZendeskDealOutput } from '@crm/deal/services/zendesk/types';
import { ZohoDealOutput } from '@crm/deal/services/zoho/types';
import { CloseDealOutput } from '@crm/deal/services/close/types';
import {
HubspotEngagementInput,
HubspotEngagementOutput,
Expand All @@ -39,6 +45,10 @@ import {
ZohoEngagementInput,
ZohoEngagementOutput,
} from '@crm/engagement/services/zoho/types';
import {
CloseEngagementInput,
CloseEngagementOutput,
} from '@crm/engagement/services/close/types';
import {
HubspotNoteInput,
HubspotNoteOutput,
Expand All @@ -52,6 +62,10 @@ import {
ZendeskNoteOutput,
} from '@crm/note/services/zendesk/types';
import { ZohoNoteInput, ZohoNoteOutput } from '@crm/note/services/zoho/types';
import {
CloseNoteInput,
CloseNoteOutput,
} from '@crm/note/services/close/types';
import {
HubspotStageInput,
HubspotStageOutput,
Expand Down Expand Up @@ -81,6 +95,10 @@ import {
ZendeskTaskOutput,
} from '@crm/task/services/zendesk/types';
import { ZohoTaskInput, ZohoTaskOutput } from '@crm/task/services/zoho/types';
import {
CloseTaskInput,
CloseTaskOutput,
} from '@crm/task/services/close/types';
import {
HubspotUserInput,
HubspotUserOutput,
Expand All @@ -90,6 +108,10 @@ import {
PipedriveUserOutput,
} from '@crm/user/services/pipedrive/types';
import { ZohoUserInput, ZohoUserOutput } from '@crm/user/services/zoho/types';
import {
CloseUserInput,
CloseUserOutput,
} from '@crm/user/services/close/types';
import {
ZendeskContactInput,
ZendeskContactOutput,
Expand All @@ -107,43 +129,49 @@ export type OriginalContactInput =
| ZohoContactInput
| ZendeskContactInput
| PipedriveContactInput
| AttioContactInput;
| AttioContactInput
| CloseContactInput;

/* deal */
export type OriginalDealInput =
| HubspotDealOutput
| ZohoDealOutput
| ZendeskDealOutput
| PipedriveDealOutput;
| PipedriveDealOutput
| CloseDealOutput;

/* company */
export type OriginalCompanyInput =
| HubspotCompanyOutput
| ZohoCompanyOutput
| ZendeskCompanyOutput
| PipedriveCompanyOutput
| AttioCompanyOutput;
| AttioCompanyOutput
| CloseCompanyOutput;

/* engagement */
export type OriginalEngagementInput =
| HubspotEngagementInput
| ZohoEngagementInput
| ZendeskEngagementInput
| PipedriveEngagementInput;
| PipedriveEngagementInput
| CloseEngagementInput;

/* note */
export type OriginalNoteInput =
| HubspotNoteInput
| ZohoNoteInput
| ZendeskNoteInput
| PipedriveNoteInput;
| PipedriveNoteInput
| CloseNoteInput;

/* task */
export type OriginalTaskInput =
| HubspotTaskInput
| ZohoTaskInput
| ZendeskTaskInput
| PipedriveTaskInput;
| PipedriveTaskInput
| CloseTaskInput;

/* stage */
export type OriginalStageInput =
Expand All @@ -159,7 +187,8 @@ export type OriginalUserInput =
| HubspotUserInput
| ZohoUserInput
| ZendeskUserInput
| PipedriveUserInput;
| PipedriveUserInput
| CloseUserOutput;

export type CrmObjectInput =
| OriginalContactInput
Expand All @@ -178,43 +207,49 @@ export type OriginalContactOutput =
| ZohoContactOutput
| ZendeskContactOutput
| PipedriveContactOutput
| AttioContactOutput;
| AttioContactOutput
| CloseContactOutput;

/* deal */
export type OriginalDealOutput =
| HubspotDealOutput
| ZohoDealOutput
| ZendeskDealOutput
| PipedriveDealOutput;
| PipedriveDealOutput
| CloseDealOutput;

/* company */
export type OriginalCompanyOutput =
| HubspotCompanyOutput
| ZohoCompanyOutput
| ZendeskCompanyOutput
| PipedriveCompanyOutput
| AttioCompanyOutput;
| AttioCompanyOutput
| CloseCompanyOutput;

/* engagement */
export type OriginalEngagementOutput =
| HubspotEngagementOutput
| ZohoEngagementOutput
| ZendeskEngagementOutput
| PipedriveEngagementOutput;
| PipedriveEngagementOutput
| CloseEngagementOutput;

/* note */
export type OriginalNoteOutput =
| HubspotNoteOutput
| ZohoNoteOutput
| ZendeskNoteOutput
| PipedriveNoteOutput;
| PipedriveNoteOutput
| CloseNoteOutput;

/* task */
export type OriginalTaskOutput =
| HubspotTaskOutput
| ZohoTaskOutput
| ZendeskTaskOutput
| PipedriveTaskOutput;
| PipedriveTaskOutput
| CloseTaskOutput;

/* stage */
export type OriginalStageOutput =
Expand All @@ -230,7 +265,8 @@ export type OriginalUserOutput =
| HubspotUserOutput
| ZohoUserOutput
| ZendeskUserOutput
| PipedriveUserOutput;
| PipedriveUserOutput
| CloseUserInput;

export type CrmObjectOutput =
| OriginalContactOutput
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/crm/company/company.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { PipedriveService } from './services/pipedrive';
import { ZendeskService } from './services/zendesk';
import { ZohoService } from './services/zoho';
import { AttioService } from './services/attio';
import { CloseService } from './services/close';

@Module({
imports: [
Expand All @@ -38,6 +39,7 @@ import { AttioService } from './services/attio';
PipedriveService,
HubspotService,
AttioService,
CloseService,
],
exports: [
SyncService,
Expand Down
Loading

0 comments on commit f88d7e4

Please sign in to comment.