@devrev-growth/snap-in-utils
v5.0.7
Published
Collection of helper functions for devrev snap-ins
Downloads
165
Readme
Overview
This package is a collection of helper functions we share between DevRev snap-ins
NOTE: Depreciated APIs
In the 4.x release, we've depreciated the old DevRev and Outreach clients. These clients were created with the createDevRevClient()
and createOutreachClient()
functions. Please use the new DevRevAPI object instead (created with new DevRevAPI(token)
)
Installation
npm i -S @devrev-growth/snap-in-utils
Upgrading
npm update @devrev-growth/snap-in-utils
Usage
Each of the remote destinations supported have their own client that requires configuration before use.
BigQuery
import { createBQClient } from '@devrev-growth/snap-in-utils';
const client = createBqClient(GOOGLE_API_KEY, PROJECT_ID);
const query =
'SELECT * FROM `bigquery-public-data.covid19_nyt.us_counties` LIMIT 10';
const results = await client.executeQuery(query);
The executeQuery
method will also format the data, returning a list of objects where the keys are the values of the columns in the query. You can also use executeQueryRaw
and formatData
if you wish to handle this on your own
DevRev
import { createDevRevClient } fromn '@devrev-growth/snap-in-utils';
const client = createDevRevClient(DEVREV_API_TOKEN);
const contact = client.getContactById(CONTACT_ID);
const {contact, account} = client.getContactAndAccount(EMAIL_ADDRESS);
By default, the client will have a 40000ms timeout on requests and be limited to 10 requests per second. It also uses the prod api https://api.devrev.ai
by default. You can override these with the timeout
maxRequests
and baseURL
options
const client = createDevRevClient(DEVREV_API_TOKEN, {
timeout: 60000,
maxRequests: 4,
baseURL: 'https://api.dev.devrev-eng.ai',
});
If you need to get all of something, you can use the special getAll
method. This will handle pagination for you and return a list of all the results, using the API name
const allAccounts = client.getAll('accounts');
// Some API endpoints have an extra bit in the path, like rev-users.all.
// This will be handled properly by the code
const allRevUsers = client.getAll('rev-users.all');
The most important functions are the getContactAndAccount
and the getOrCreateContactAndAccount
. This will handle Contact and Account resolution for you, just provide whatever info you can will do the rest. The major difference is that getOrCreateContactAndAccount
will create a new Contact and Account if one does not exist. It accepts an optional object at the end to provide additional information to create the Contact and Account
const { contact, account } = client.getContactAndAccount(EMAIL_ADDRESS);
const { contact, account } = client.getContactAndAccount(EMAIL_ADDRESS, DOMAIN);
const { contact, account } = client.getOrCreateContactAndAccount(EMAIL_ADDRESS);
const { contact, account } = client.getOrCreateContactAndAccount(
EMAIL_ADDRESS,
DOMAIN
);
const { contact, account } = client.getOrCreateContactAndAccount(
EMAIL_ADDRESS,
DOMAIN,
{ full_name: NAME, company: COMPANY }
);
Beyond these special functions, there should be get and create for all the major workflows we need (and if not we should add them)
getAccountsByDomain,
getAccountById,
getContactById,
getRevOrgById,
getRevOrgsByAccount,
getContactsByEmail,
getDevUserById,
getDevUsersByEmail,
getEngagementById,
getEngagementsByExternalRef,
getContactsByRevOrg,
getContactsByAccount,
getContactAndAccount,
getOrCreateContactAndAccount,
deleteContact,
deleteAccount,
deleteEngagement,
getAll,
updateRevOrg,
updateContact,
updateAccount,
updateEngagement,
createEngagement,