Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Add integration with Close CRM #484

Merged
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 @@ -85,10 +85,7 @@ export class CloseConnectionService implements ICrmConnectionService {
},
);
const data: CloseOAuthResponse = res.data;
this.logger.log(
'OAuth credentials : close ticketing ' + JSON.stringify(data),
);

this.logger.log('OAuth credentials : close CRM ' + JSON.stringify(data));
let db_res;
const connection_token = uuidv4();

Expand All @@ -100,7 +97,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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify the computed expression for better readability.

- account_url: CONNECTORS_METADATA['crm']['close']?.urls?.apiUrl
+ account_url: CONNECTORS_METADATA.crm.close?.urls?.apiUrl
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
account_url: CONNECTORS_METADATA['crm']['close']?.urls?.apiUrl,
account_url: CONNECTORS_METADATA.crm.close?.urls?.apiUrl,
Tools
Biome

[error] 103-103: The computed expression can be simplified without the use of a string literal. (lint/complexity/useLiteralKeys)

Unsafe fix: Use a literal key instead.


[error] 103-103: The computed expression can be simplified without the use of a string literal. (lint/complexity/useLiteralKeys)

Unsafe fix: Use a literal key instead.

expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_in) * 1000,
),
Expand Down Expand Up @@ -153,10 +150,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 +165,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
74 changes: 58 additions & 16 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 All @@ -68,6 +82,10 @@ import {
ZohoStageInput,
ZohoStageOutput,
} from '@crm/stage/services/zoho/types';
import {
CloseStageInput,
CloseStageOutput,
} from '@crm/stage/services/close/types';
import {
HubspotTaskInput,
HubspotTaskOutput,
Expand All @@ -81,6 +99,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 +112,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,50 +133,57 @@ 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 =
| HubspotStageInput
| ZohoStageInput
| ZendeskStageInput
| PipedriveStageInput;
| PipedriveStageInput
| CloseStageInput;

/* engagementType */

Expand All @@ -159,7 +192,8 @@ export type OriginalUserInput =
| HubspotUserInput
| ZohoUserInput
| ZendeskUserInput
| PipedriveUserInput;
| PipedriveUserInput
| CloseUserOutput;

export type CrmObjectInput =
| OriginalContactInput
Expand All @@ -178,50 +212,57 @@ 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 =
| HubspotStageOutput
| ZohoStageOutput
| ZendeskStageOutput
| PipedriveStageOutput;
| PipedriveStageOutput
| CloseStageOutput;

/* engagementType */

Expand All @@ -230,7 +271,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
Loading