npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

legacy-api-to-salesforce-facilitator

v1.0.4

Published

tool used for existing API integrations to correctly interact with the correct data source when transitioning from a legacy API to Salesforce without having to make changes for the current integrated services.

Readme

legacy-api-to-salesforce-facilitator

Explanation

there may be is an interrim time where it is necessary to have both systems active while transitioning from a legacy db and restful API app to salesforce.

The aim of this package is to aid in this transition by encapulsating the salesforce restful apex apis and providing a switch function to allow the consumer of this package to switch which function (legacy or salesforce) is exected based off of supplied existence checks.

By including these functions into the existing legacy API, all currently integrated services connecting to the legacy API can continue working without making changes as the legacy API will correctly input the incoming data in the appropriate place (salesforce or legacy DB).

Steps To Use:

  1. Provide env vars in the project

  2. Import the restful api functions as needed

  3. Define legacy and salesforce existence check fuctions

  4. Define legacy and salesforce functions

  5. Provide the previously defined functions in step 3 and 4 to the checkAndExecuteLegacyOrSalesforceFunction method as anonymous functions

Provided Functions:

  • getSalesforceAuthToken:

returns the salesforce auth token. sets it in to local cache for future reuse to prevent multiple auth calls.

this method is exposed to allow the user to get an auth token on it's own if necessary.

By exposing this function, users can bypass the he local cache functionality and call this method directly to add the token to their respective rest calls (token is given as a optional param)

@returns token for salesforce Authentication

  • checkAndExecuteLegacyOrSalesforceFunction:

This function is the main function used for this package. By defining the below parameter functions, current API's can still be utilitzed by all integrating services while transitioning data from a legacy system to salesforce.

The goal of this package is to slowly allow a legacy system to decouple from current integrated services seamlessly when transitioning to salesforce.

@param {*} legacyCheck a function that checks for object existence in legacy DB. pass in an anonymous function.

@param {*} salesForceCheck a function that checks for object existence in salesforce DB. pass in an anonymous function.

@param {*} legacyFunc a function that performs the legacy API interaction with the legacy DB. This function would contain all previous API interactions. pass in an anonymous function.

@param {*} salesForceFunc a function that performs the same API interaction as the legacy API interaction but with the salesforce DB. This function would contain all previous API interactions but interact with the salesforce DB. pass in an anonymous function.

@returns the output of the executed function.

  • getSalesforceData:

provide sa GET endpoint wrapper to interact with salesforces endpoints in Node.

@param {*} endpoint pass in the salesforce endpoint that is expecting a GET. Do not include the base url as provided in env vars (see readMe).

@param {*} token optional parameter set to null. will check localCache to see if token is present. if not will retrieve and store in cache.

@returns the output object of the GET salesforce endpoint.

  • putSalesforceData:

provides a PUT endpoint wrapper to interact with salesforces endpoints in Node.

@param {*} endpoint pass in the salesforce endpoint that is expecting a PUT. Do not include the base url as provided in env vars (see readMe). @param {*} body the body of the PUT call. expecting a json object that matches the expected salesforce input (verify in salesforce the expected body) @param {*} token optional parameter set to null. will check localCache to see if token is present. if not will retrieve and store in cache.

@returns sucessful or unsuccessful message

  • postSalesforceData:

provides a POST endpoint wrapper to interact with salesforces endpoints in Node.

@param {*} endpoint pass in the salesforce endpoint that is expecting a POST. Do not include the base url as provided in env vars (see readMe).

@param {*} body the body of the POST call. expecting a json object that matches the expected salesforce input (verify in salesforce the expected body)

@param {*} token optional parameter set to null. will check localCache to see if token is present. if not will retrieve and store in cache.

@returns sucessful or unsuccessful message

  • NOTE: delete function is not supplied.

the following environment variables are needed:

// sales force grant type (typically 'client_credentials')
SALESFORCE_GRANT_TYPE

// client id provided by salesforce
SALESFORCE_CLIENT_ID

// client secret provided by salesforce
SALESFORCE_CLIENT_SECRET

// salesforce base url to use with endpoints 
SALESFORCE_BASE_URL

Example Usage:

const legacyDBInteraction = async (params) => {
  const data = await legacyQuery(params);
  return data;
}

const salesforceDBInteraction = async (appId) => {
  const url = `${process.env.SALESFORCE_BASE_URL}${PutNewInfoEndpoint}`;
  const body = { app_id: `${appId}` };
  const data = await putSalesforceData(url, body);
  return data;
}

const legacyAppCheck = async (uuid) => {
  const record = legacyDBAppLookup(uuid);
  return record ? true : false;
}

const sfAppCheck = async (uuid) => {
  const sfRecord = await getSalesforceData(`${process.env.SALESFORCE_BASE_URL}${SF_GET_BY_UUID(UUID)}`);
  return sfRecord ? true : false;
}

//every service calling this api endpoint will have their data correctly put into the corresponding data source. 
const apiCall = async (req, res, next) => {
  try {
    const { uuid } = req.params;
    const legacyCheck = async () => { await legacyAppCheck(uuid); }
    const sfCheck = async () => { await sfAppCheck(uuid); }
    const legacyWrapper = async () => { await legacyDBInteraction(uuid); }
    const salesforceWrapper = async () => { await salesforceDBInteraction(uuid); }
    await checkAndExecuteLegacyOrSalesforceFunction(legacyCheck, sfCheck, legacyWrapper, salesforceWrapper);
    return res.sendStatus(204);
  } catch (error) {
    return next(error);
  }
};

Recomendations:

  • create a salesforce folder
  • add an endpoints file there with each endpoint defined as either a string or a func that returns a string.
  • add a util file there with the existance checks