@apexdevtools/sfdx-auth-helper
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

sfdx-auth-helper

Authentication support library for sfdx.

Usage

To start, create an instance of the helper at the path of your sf project.

  // dir containing sfdx-project.json
  const workspacePath = '/path/to/my/project';
  const helper = await AuthHelper.instance(workspacePath);
  • Get connection to an org (That exists in sf config)
  // Connection.create(...) with default user auth info
  const conn = helper.connect();
  // Get an existing saved org by specific username or alias
  helper.connect('user@mycompany.org');
  helper.connect('MyOrg');
  • Get a jsforce connection to current default org
  // new jsforce.Connection with default user auth info
  const conn = helper.connectJsForce();

  // Also supports alias / username
  helper.connectJsForce('MyOrg');
  // Provide fallback API version if none set in project
  helper.connectJsForce('MyOrg', '57.0');
  • Transform an existing Connection into a jsforce one
  // Connection created by newer version of `@salesforce/core`
  const conn = Connection.create({...});

  // Use static to produce a jsforce.Connection
  AuthHelper.toJsForceConnection(conn);
  • Additional instance methods
    • getDefaultUsername() - This returns the default org username for a sfdx workspace. If no default username is set it returns undefined. If the default is an org alias that is translated to a username.
    • reloadConfig() - If the loaded config has changed due to some external action (e.g. org creation) the copy cached by the core library will be stale. Use this to reload, making a new helper instance will not be enough.

Development

Building

This project uses the pnpm package manager.

  pnpm build

To run unit tests:

  pnpm test

To test bundling using webpack:

  pnpm test:pack
  node test-bundle/bundle.js

This should execute without error.

Git Hooks

If you encounter difficulties with the installed git hooks, they can be bypassed with --no-verify/-n flag on commit. To disable them completely (after install) use npx husky uninstall or the direct command git config --unset core.hooksPath.

License

All the source code included uses a 3-clause BSD license, see LICENSE for details.

Readme

Keywords

Package Sidebar

Install

npm i @apexdevtools/sfdx-auth-helper

Weekly Downloads

3

Version

2.1.0

License

BSD-3-Clause

Unpacked Size

23 kB

Total Files

11

Last publish

Collaborators

  • apexdevtools