Skip to content

Commit

Permalink
Merge pull request #156 from panoratech/feat/field-providers
Browse files Browse the repository at this point in the history
Feat/field providers
  • Loading branch information
naelob authored Dec 12, 2023
2 parents c415930 + d2a73a2 commit 96a1357
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 38 deletions.
3 changes: 1 addition & 2 deletions apps/frontend-snippet/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ export const providersConfig: ProvidersConfig = {
authBaseUrl: '',
logoPath: 'assets/crm/freshsales_logo.webp',
},
//TODO
'zendesk': {
clientId: '26cd23a81a8fefc134edec2c533a1cb1761d359cfcf438fc159543931e92fc93',
scopes: 'read write',
authBaseUrl: 'https://api.getbase.com/oauth2/authorize',//'https://api.getbase.com/oauth2/authorize',
authBaseUrl: 'https://api.getbase.com/oauth2/authorize',
logoPath: 'assets/crm/zendesk_logo.png',
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class PipedriveConnectionService {
},
},
);
//TODO: handle if res throws an error
const data: PipeDriveOAuthResponse = res.data;
this.logger.log('OAuth credentials : pipedrive ');
const db_res = await this.prisma.connections.upsert({

Check warning on line 56 in packages/api/src/@core/connections/crm/services/pipedrive/pipedrive.service.ts

View workflow job for this annotation

GitHub Actions / Build and Test (16.x)

'db_res' is assigned a value but never used

Check warning on line 56 in packages/api/src/@core/connections/crm/services/pipedrive/pipedrive.service.ts

View workflow job for this annotation

GitHub Actions / release

'db_res' is assigned a value but never used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ export class ZendeskConnectionService {
},
},
);
//TODO: handle if res throws an error
const data: ZendeskOAuthResponse = res.data;
this.logger.log('OAuth credentials : zendesk ' + JSON.stringify(data));
//todo: refresh token + expiration timestamp
// save tokens for this customer inside our db

const db_res = await this.prisma.connections.upsert({
where: {
id_connection: isNotUnique.id_connection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class FieldMappingService {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: providerId.toLowerCase(),
},
});

Expand Down
16 changes: 8 additions & 8 deletions packages/api/src/@core/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,21 @@ export type UnifySourceType =

export const domains = {
CRM: {
hubspot: 'https://api.hubapi.com/',
zoho: 'https://www.zohoapis.com/crm/v3/',
zendesk: '', // TODO
hubspot: 'https://api.hubapi.com',
zoho: 'https://www.zohoapis.eu/crm/v3',
zendesk: 'https://api.getbase.com/v2',
freshsales: '',
pipedrive: '',
pipedrive: 'https://api.pipedrive.com',
},
};

export const customPropertiesUrls = {
CRM: {
hubspot: `${domains['CRM']['hubspot']}/properties/v1/contacts/properties`,
zoho: `${domains['CRM']['zoho']}`, // TODO
zendesk: `${domains['CRM']['zendesk']}`,
freshsales: `${domains['CRM']['freshsales']}`,
pipedrive: `${domains['CRM']['pipedrive']}`,
zoho: `${domains['CRM']['zoho']}/settings/fields?module=Contact`,
zendesk: `${domains['CRM']['zendesk']}/contact/custom_fields`,
freshsales: `${domains['CRM']['freshsales']}`, //TODO
pipedrive: `${domains['CRM']['pipedrive']}/v1/personFields`,
},
};

Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/crm/contact/services/contact.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ export class ContactService {
contacts: unifiedContacts,
};

//TODO
/*if (remote_data) {
const resp = await this.prisma.remote_data
res = {
...res,
remote_data: [resp.data],
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/crm/contact/services/freshsales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class FreshSalesService {
}
}

async getContacts(
async syncContacts(
linkedUserId: string,
): Promise<ApiResponse<FreshsalesContactOutput[]>> {
try {
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/crm/contact/services/hubspot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class HubspotService {
return;
}

async getContacts(
async syncContacts(
linkedUserId: string,
custom_properties?: string[],
): Promise<ApiResponse<HubspotContactOutput[]>> {
Expand Down Expand Up @@ -90,6 +90,8 @@ export class HubspotService {
Authorization: `Bearer ${decrypt(connection.access_token)}`,
},
});
this.logger.log(`Synced hubspot contacts !`);

return {
data: resp.data.results,
message: 'Hubspot contacts retrieved',
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/crm/contact/services/pipedrive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class PipedriveService {
return;
}

async getContacts(
async syncContacts(
linkedUserId: string,
): Promise<ApiResponse<PipedriveContactOutput[]>> {
try {
Expand Down
22 changes: 19 additions & 3 deletions packages/api/src/crm/contact/services/pipedrive/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,40 @@ import {

export function mapToContact_Pipedrive(
source: UnifiedContactInput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): PipedriveContactInput {
// Assuming 'email_addresses' and 'phone_numbers' arrays contain at least one entry
const primaryEmail = source.email_addresses?.[0]?.email_address;
const primaryPhone = source.phone_numbers?.[0]?.phone_number;

// Convert to Pipedrive format if needed
const emailObject = primaryEmail
? [{ value: primaryEmail, primary: true, label: '' }]
: [];
const phoneObject = primaryPhone
? [{ value: primaryPhone, primary: true, label: '' }]
: [];

return {
const result: PipedriveContactInput = {
name: `${source.first_name} ${source.last_name}`,
email: emailObject,
phone: phoneObject,
};

if (customFieldMappings && source.field_mappings) {
for (const fieldMapping of source.field_mappings) {
for (const key in fieldMapping) {
const mapping = customFieldMappings.find(
(mapping) => mapping.slug === key,
);
if (mapping) {
result[mapping.remote_id] = fieldMapping[key];
}
}
}
}
return result;
}

export function mapToUnifiedContact_Pipedrive(
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/pipedrive/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface PipedriveContact {
org_name: string;
owner_name: string;
cc_email: string;
[key: string]: any;
}

export type PipedriveContactInput = Partial<PipedriveContact>;
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/crm/contact/services/zendesk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class ZendeskService {
return;
}

async getContacts(
async syncContacts(
linkedUserId: string,
): Promise<ApiResponse<ZendeskContactOutput[]>> {
try {
Expand All @@ -80,6 +80,8 @@ export class ZendeskService {
const finalData = resp.data.items.map((item) => {
return item.data;
});
this.logger.log(`Synced zendesk contacts !`);

return {
data: finalData,
message: 'Zendesk contacts retrieved',
Expand Down
21 changes: 20 additions & 1 deletion packages/api/src/crm/contact/services/zendesk/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,37 @@ import {

export function mapToContact_Zendesk(
source: UnifiedContactInput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): ZendeskContactInput {
// Assuming 'email_addresses' array contains at least one email and 'phone_numbers' array contains at least one phone number
const primaryEmail = source.email_addresses?.[0]?.email_address;
const primaryPhone = source.phone_numbers?.[0]?.phone_number;

return {
const result: ZendeskContactInput = {
name: `${source.first_name} ${source.last_name}`,
first_name: source.first_name,
last_name: source.last_name,
email: primaryEmail,
phone: primaryPhone,
};

if (customFieldMappings && source.field_mappings) {
for (const fieldMapping of source.field_mappings) {
for (const key in fieldMapping) {
const mapping = customFieldMappings.find(
(mapping) => mapping.slug === key,
);
if (mapping) {
result.custom_fields[mapping.remote_id] = fieldMapping[key];
}
}
}
}

return result;
}

export function mapToUnifiedContact_Zendesk(
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/zendesk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ZendeskContact {
name: string;
creator_id: number;
meta: Meta;
custom_fields: Record<string, any>;
}

export type ZendeskContactInput = Partial<ZendeskContact>;
Expand Down
5 changes: 3 additions & 2 deletions packages/api/src/crm/contact/services/zoho/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ZohoService {
return;
}

async getContacts(
async syncContacts(
linkedUserId: string,
): Promise<ApiResponse<ZohoContactOutput[]>> {
try {
Expand All @@ -81,7 +81,8 @@ export class ZohoService {
},
},
);
this.logger.log('CONTACTS ZOHO ' + JSON.stringify(resp.data.data));
//this.logger.log('CONTACTS ZOHO ' + JSON.stringify(resp.data.data));
this.logger.log(`Synced zoho contacts !`);
return {
data: resp.data.data,
message: 'Zoho contacts retrieved',
Expand Down
21 changes: 20 additions & 1 deletion packages/api/src/crm/contact/services/zoho/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,36 @@ import {

export function mapToContact_Zoho(
source: UnifiedContactInput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): ZohoContactInput {
// Assuming 'email_addresses' array contains at least one email and 'phone_numbers' array contains at least one phone number
const primaryEmail = source.email_addresses?.[0]?.email_address;
const primaryPhone = source.phone_numbers?.[0]?.phone_number;

return {
const result: ZohoContactInput = {
First_Name: source.first_name,
Last_Name: source.last_name,
Email: primaryEmail,
Phone: primaryPhone,
};

if (customFieldMappings && source.field_mappings) {
for (const fieldMapping of source.field_mappings) {
for (const key in fieldMapping) {
const mapping = customFieldMappings.find(
(mapping) => mapping.slug === key,
);
if (mapping) {
result[mapping.remote_id] = fieldMapping[key];
}
}
}
}

return result;
}

export function mapToUnifiedContact_Zoho(
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/zoho/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface ZohoContact {
Other_Country: string;
Description: string;
Record_Image: string;
[key: string]: any;
}

export type ZohoContactInput = Partial<ZohoContact>;
Expand Down
Loading

0 comments on commit 96a1357

Please sign in to comment.