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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsforce-connection

v2.1.0

Published

Create an instantly reliable jsforce connection

Downloads

127

Readme

jsforce-connection

Create an instantly reliable jsforce connection.

Build Status

Get a promise for an authenticated jsforce connection based on the SALESFORCE_URL env variable or config JSON.

Exclusively uses the user account's Salesforce instance URL, e.g. https://na30.salesforce.com, to avoid race conditions with replication to the centralized login service, e.g. htttps://login.salesforce.com.

Install

npm install jsforce jsforce-connection --save

Usage

See: jsforce docs for how to use a connection, once established.

Create a connection

⚠️ Previous versions of this module would cache the connection. This is no longer the case. If you need a reusable singleton, then cache & share the connection outside of this module.

with SALESFORCE_URL environment variable

  • Must include oAuth client ID, secret, & refresh token
  • Example: force://{client-id}:{secret}:{refresh-token}@{instance-name}.salesforce.com

Example to get a connection:

const createConnection = require('jsforce-connection').default;

createConnection()
  .then( salesforceApi => {
    console.log(`jsforce connected to ${salesforceApi.instanceUrl}`)
  });

Example to get a connection & user identity info:

const createConnectionAndIdentity = require('jsforce-connection').connectionAndIdentity;

createConnectionAndIdentity()
  .then( { connection: salesforceApi, identity } => {
    console.log(`jsforce connected to ${salesforceApi.instanceUrl}`)
    console.log(`jsforce identity is ${identity.username}`)
  });

with config JSON

Example:

const createConnectionFromConfig = require('jsforce-connection').connectionFromConfig;

createConnectionFromConfig({
    clientId : 'XXXXX',
    clientSecret : '12345',
    refreshToken : 'YYYYY',
    instanceUrl : `https://naZZ.salesforce.com`
  })
  .then( salesforceApi => {
    console.log(`jsforce connected to ${salesforceApi.instanceUrl}`)
  });

API

  • .connection()
    • Get a jsforce Salesforce API connection
    • Returns a Promise for the connection
  • .connectionAndIdentity()
    • Get a jsforce Salesforce API connection & identity
    • Returns a Promise for { connection, identity }

Tips & Tricks

Handle errors

catch after connection* calls to handle errors from the async flow (log|exit|retry).

Force.com API version

Pass the API version number as the last argument to any of the connection* functions.

Example:

const createConnection = require('jsforce-connection').default;

createConnection('32.0')
  .then( salesforceApi => {
    console.log(`jsforce connected to v32.0 on ${salesforceApi.instanceUrl}`)
  });

Logging

Normally this module's behavior will be silent, no log output.

To enable logging to stderr, set environment VERBOSE=true.

⚠️ Making a change to this module? Never log to stdout, as that will pollute the output of some command-line tools that depend on this module.

Testing

Implemented with AVA, concurrent test runner.

npm test or npm run test