Authentication support library for sfdx.
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 ajsforce
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.
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.
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
.
All the source code included uses a 3-clause BSD license, see LICENSE for details.