This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
nforce8 is a Node.js REST API wrapper for Salesforce, a modernized fork of the original nforce library. It is promise-based only (no callback support). Used with NodeRED and other Node.js applications. Requires Node.js >22.0.
- Run all tests with coverage:
npm test(optional root.envis loaded via Node’s--env-file-if-exists=.envwhen present) - Run a single test file:
npx mocha test/<filename>.js(e.g.,npx mocha test/crud.js) - Lint:
npm run lintornpx eslint .(flat config ineslint.config.js)
There is no build step — this is a plain Node.js module with no transpilation.
index.js(~1089 lines) — Main module. ExportscreateConnection(),createSObject(),Record,plugin,util. Contains the Connection prototype with all Salesforce API methods (auth, CRUD, query, streaming).lib/connection.js— ES6 Connection class with options validation (clientId, redirectUri, environment, mode, apiVersion format).lib/record.js— SObject record class with field change tracking. Supportsget(),set(),getId(), and attachment handling.
lib/fdcstream.js— Faye-based Streaming API client (EventEmitter).SubscriptionandClientclasses with replay and auto-reconnection support.lib/optionhelper.js— Builds API request options (URIs, headers, multipart, gzip).lib/multipart.js— Multipart form-data builder for file uploads (ContentVersion, Attachment).lib/util.js— Type checking, response validation, OAuth validation, ID extraction.lib/constants.js— OAuth endpoints, API versions, environment/mode defaults.lib/errors.js— Custom error factories (nonJsonResponse, invalidJson, emptyResponse).
- Single vs Multi-user mode: In single mode, OAuth is cached in the connection object. In multi mode, OAuth must be passed with each operation.
- Auto token refresh: Handles INVALID_SESSION_ID and Bad_OAuth_Token errors. Retries once with refreshed token when
autoRefresh: true. - Plugin system: Extensible via
nforce.plugin()to add methods to the Connection prototype. - API version format: Must be fully-qualified string like
"v45.0"— bare numbers are rejected.
- Framework: Mocha + should.js assertions + NYC coverage
- Mock server: Tests run against a local HTTP mock Salesforce API (
test/mock/), not a live org. - Test files:
test/crud.js,test/query.js,test/record.js,test/connection.js,test/errors.js,test/integration.js,test/plugin.js
- GitHub Actions:
codecheck.ymlruns tests on push to main/master/develop;publish.ymlpublishes to npm on release. - npm publish from CI: set secret
NPM_TOKEN(granular write fornforce8or classic Automation).NODE_AUTH_TOKENmust be set at job level sosetup-nodewrites.npmrc(seedocs/npm-publish-github-actions.md). - Coverage uploaded to Codecov.
ESLint 10 with flat config (eslint.config.js): eslint:recommended rules plus quotes (single), wrap-iife, yoda (never), etc. Main code uses Node + Mocha globals; examples/** is linted with no-undef / no-unused-vars off for snippet-style scripts.