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

sf-bulk2-query

v1.0.1

Published

Salesforce Bulk API 2.0 Query utility

Readme

SF-Bulk2-Query

A Javascript module for querying with the Salesforce Bulk API 2.0

Features

  • Authenticate with Salesforce using username, password, security token, client key and secret.

  • Execute SOQL queries using the Bulk API 2.0.

  • Retrieve job results as a stream, file, or raw data.

Installation

npm install sf-bulk2-query

Usage

Salesforce Credentials Class

Represents the credentials needed to connect to Salesforce.

import { SalesforceCredentials } from 'sf-bulk2-query';

const creds = new SalesforceCredentials(
'your_username',
'your_password',
'your_security_token',
'your_client_id',
'your_client_secret'
);

Bulk API Client

import SalesforceBulkApiClient from 'sf-bulk2-query';

const client = new SalesforceBulkApiClient('https://login.salesforce.com', '58.0', creds);
await client.login();
await client.bulkQueryToFile('SELECT Id, Name FROM Account', './accounts.csv');

API Documentation

Constructor

const client = new SalesforceBulkApiClient(salesforceInstance, apiVersion, creds);

salesforceInstance

The URL of your Salesforce instance (e.g., 'https://login.salesforce.com' or 'https://yourinstance.my.salesforce.com').

Defaults to 'https://login.salesforce.com'.

apiVersion

The Salesforce API version to use. Defaults to '58.0'.

creds

An instance of SalesforceCredentials.

Attibutes

pollTime

The frequncy of job polling in milliseconds. Defaults to 10 seconds

Methods

login (async) : void

await client.login(creds);

creds

Optional: An instance of SalesforceCredentials.

If creds are provided then it will use the newly passes credentials, else it will used those passed during the constructor. If there are no creds an error will be thrown.

async bulkQueryAsStream(query, options) : stream

let dataStream = await client.bulkQueryAsStream(query, options);

query

A SOQL Query

options

Defaults to { allRows = false, pageSize = null }

allRows

Optional: Boolean If passed True then will use the all rows flag to the bulk api allowing the return of deleted and archived data.

pageSize

Optional: Integer
If passed will pull results in chunks the size of the int.

async bulkQueryToFile(query, filename, options) : void

let dataStream = await client.bulkQueryToFile(query, filename, options);

query

A SOQL Query

filename

A file path for writing the results to disk.

Will override an existing file.

options

Defaults to { allRows = false, pageSize = null }

allRows

Optional: Boolean If passed True then will use the all rows flag to the bulk api allowing the return of deleted and archived data.

pageSize

Optional: Integer
If passed will pull results in chunks the size of the int.

Advanced Methods

startBulkQuery (async) : request

let resp = await client.startBulkQuery(query, allRows);

query

A SOQL Query

allRows

Optional: Boolean.
If passed True then will use the all rows flag to the bulk api allowing the return of deleted and archived data.

resp
{
    status,
    statusText,
    headers,
    body
}

checkJobStatus (async) : response

let resp = await client.checkJobStatus(jobId);

jobId

Salesforce Bulk API Job Id - Returned from executeBulkQuery body.id

resp

fetch response.json()

pollJobTillComplete (async) : response

let resp = await client.pollJobTillComplete(jobId, pollTime);

jobId

Salesforce Bulk API Job Id - Returned from executeBulkQuery body.id

pollTime

Optional : Time in milliseconds. If not passed defaults to client.pollTime

resp

The jobs state as defined https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/query_get_one_job.htm

retrieveJobResults_sequentialStream (async) : stream

let resp = await client.retrieveJobResults_sequentialStream(jobId);

Returns a data stream that will pipe the csv like text as the results are retrieved.