Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/backend/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Request, Response } from 'express';
export type CRM_TP_ID = 'zohocrm' | 'sfdc' | 'pipedrive' | 'hubspot' | 'closecrm' | 'ms_dynamics_365_sales';
export type CHAT_TP_ID = 'slack' | 'discord';
export type ACCOUNTING_TP_ID = 'quickbooks' | 'xero';
export type ATS_TP_ID = 'greenhouse' | 'lever';
export type ATS_TP_ID = 'greenhouse' | 'lever' | 'workable';
export type TICKET_TP_ID = 'linear' | 'clickup' | 'asana' | 'jira' | 'trello' | 'bitbucket' | 'github';

export const DEFAULT_SCOPE = {
Expand Down Expand Up @@ -54,6 +54,7 @@ export const DEFAULT_SCOPE = {
[TP_ID.quickbooks]: ['com.intuit.quickbooks.accounting'],
[TP_ID.xero]: ['offline_access', 'accounting.contacts', 'accounting.transactions', 'accounting.settings'],
[TP_ID.greenhouse]: [],
[TP_ID.workable]: ['r_jobs', 'r_candidates', 'r_account', 'w_candidates', 'w_departments'],
[TP_ID.lever]: [
'applications:read:admin',
'archive_reasons:read:admin',
Expand Down Expand Up @@ -106,6 +107,7 @@ export const mapIntegrationIdToIntegrationName = {
[TP_ID.quickbooks]: 'QuickBooks',
[TP_ID.xero]: 'Xero',
[TP_ID.greenhouse]: 'Greenhouse',
[TP_ID.workable]: 'Workable',
[TP_ID.lever]: 'Lever',
[TP_ID.github]: 'GitHub',
};
Expand Down Expand Up @@ -219,6 +221,8 @@ export const objectNameMapping: Record<string, Record<CRM_TP_ID, string | undefi
export interface AppConfig {
bot_token?: string;
org_url?: string;
subdomain?: string;
account_subdomain?: string;
env?: string;
}

Expand Down
96 changes: 96 additions & 0 deletions packages/backend/helpers/ats/workable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { AppConfig } from '../../constants/common';

type WorkableConfig = AppConfig & {
subdomain?: string;
account_subdomain?: string;
};

type WorkableConnection = {
app_config?: unknown;
tp_account_url?: string | null;
app?: {
app_config?: unknown;
} | null;
};

export const getWorkableConfig = (connection: WorkableConnection): WorkableConfig => {
return ((connection.app_config || connection.app?.app_config || {}) as WorkableConfig) || {};
};

export const getWorkableSubdomain = (connection: WorkableConnection): string => {
const config = getWorkableConfig(connection);
const configuredValue = config.subdomain || config.account_subdomain || config.org_url || connection.tp_account_url;

if (!configuredValue) {
throw new Error('Workable account subdomain is required in app_config.org_url or app_config.subdomain');
}

return String(configuredValue)
.trim()
.replace(/^https?:\/\//, '')
.replace(/\/.*$/, '')
.replace(/\.workable\.com$/i, '');
};

export const getWorkableBaseUrl = (connection: WorkableConnection): string => {
return `https://${getWorkableSubdomain(connection)}.workable.com/spi/v3`;
};

export const getWorkableHeaders = (token: string) => ({
Authorization: `Bearer ${token}`,
Accept: 'application/json',
'Content-Type': 'application/json',
});

export const buildWorkableParams = ({
pageSize,
cursor,
fields,
}: {
pageSize?: number;
cursor?: unknown;
fields?: Record<string, any>;
}) => {
const params: Record<string, any> = { ...(fields || {}) };

if (pageSize && !Number.isNaN(pageSize)) {
params.limit = pageSize;
}

if (cursor) {
params.max_id = cursor;
}

return params;
};

export const getWorkableCollection = (data: any, collectionKey: string): any[] => {
if (Array.isArray(data?.[collectionKey])) {
return data[collectionKey];
}

if (Array.isArray(data?.data)) {
return data.data;
}

if (Array.isArray(data)) {
return data;
}

return [];
};

export const getWorkableNextCursor = (data: any): string | undefined => {
const next = data?.paging?.next;

if (!next) {
return undefined;
}

try {
const url = new URL(next);
return url.searchParams.get('max_id') || url.searchParams.get('since_id') || undefined;
} catch (_error) {
return undefined;
}
};
28 changes: 28 additions & 0 deletions packages/backend/helpers/crm/transform/disunify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,34 @@ export async function disunifyAtsObject<T extends Record<string, any>>({

return processedObj;
}

case TP_ID.workable: {
if (objType === 'candidate') {
const email = Array.isArray(obj.email_addresses)
? obj.email_addresses[0]?.value || obj.email_addresses[0]
: obj.email_addresses;
const phone = Array.isArray(obj.phone_numbers)
? obj.phone_numbers[0]?.value || obj.phone_numbers[0]
: obj.phone_numbers;
const socialLinks = Array.isArray(obj.social_media_addresses)
? obj.social_media_addresses.map((address: any) => address.value || address)
: [];
const websiteLinks = Array.isArray(obj.website_addresses)
? obj.website_addresses.map((address: any) => address.value || address)
: [];
const links = [...socialLinks, ...websiteLinks];

return {
...transformedObj,
...(email && { email }),
...(phone && { phone }),
...(links.length ? { links } : {}),
...(obj.tags && { tags: obj.tags }),
};
}

return processedObj;
}
}
}
export async function disunifyAccountingObject<T extends Record<string, any>>({
Expand Down
1 change: 1 addition & 0 deletions packages/backend/helpers/crm/transform/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ export const postprocessDisUnifyAtsObject = <T extends Record<string, any>>({
}) => {
const preprocessMap: Record<ATS_TP_ID, Record<any, Function>> = {
[TP_ID.greenhouse]: {},
[TP_ID.workable]: {},
[TP_ID.lever]: {},
};
const transformFn = (preprocessMap[tpId] || {})[objType];
Expand Down
Loading
Loading