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

@heroku/sf-fx-runtime-nodejs

v0.14.5

Published

A web server that takes in function source code and provides the Salesforce FX SDK to the invoked source code.

Downloads

592

Maintainers

jesse.brown-sfjesse.brown-sfmgomes-herokumgomes-herokusruthichsruthichmarcusblankenshipmarcusblankenshipbrittany.jonesbrittany.jonesviniljainviniljainjoshwlewis-sfdcjoshwlewis-sfdcmengxiao.zhaomengxiao.zhaodlira-sfdlira-sfjulianduque-sfdcjulianduque-sfdcnilamuthunilamuthusmrutisamantasmrutisamantajdowningjdowningdpark.herokudpark.herokunnaidu9nnaidu9cgfuhcgfuhyann_ckyann_ckjeffrey.estradajeffrey.estradacwallsfcwallsfaklimaiteaklimaiterishabh.wasonrishabh.wasondzuelke-sfdcdzuelke-sfdcdgallegossfdcdgallegossfdcsmukusmukukmichalskiskmichalskiscory.steelecory.steeleykatzykatzkerry-bennettkerry-bennettangelayoungangelayoungdreichenbergdreichenbergmble-sfdc-2mble-sfdc-2taylor.jonestaylor.jonessfjonnpmsfjonnpmsimonebonettisfitasimonebonettisfitakamakshinagarkamakshinagarafraidknotafraidknotvish_herokuvish_herokusarahoh2468sarahoh2468sghaffarsghaffardkabanov1dkabanov1sbosio_sfsbosio_sfangelcampbellangelcampbell7ftz7ftzsfalansfalanhillzbot2000hillzbot2000kdreyerorenkdreyerorenrcrossrcrosslsorstokkelsorstokkesudarshanhiraysudarshanhirayalex_herokualex_herokurajashri-gurusamyrajashri-gurusamymandeepsfmandeepsfmingzhi-liu1258mingzhi-liu1258beanieboibeanieboidougmcinnes-sfdcdougmcinnes-sfdcbeckychenbeckychendasofieidasofieixx-sfdc-npmxx-sfdc-npmkpremkumarkpremkumarstessema-sfcstessema-sfcchap-herokuchap-herokudhammer25dhammer25ndavidson-sfndavidson-sfumarsfdcumarsfdccdwort-sfdccdwort-sfdcapoorvasrivapoorvasrivmichellejhlimmichellejhlimjhili!16jhili!16apadalaapadalacmcclung-npm-salesforce.comcmcclung-npm-salesforce.comrstiltonsfrstiltonsftlowrimoretlowrimorerchandarchandaabhinavkoulabhinavkouldaniel.brightdaniel.brightjonnymacjonnymacjustinwilaby-sfjustinwilaby-sfcv88cv88aaronromeosfdcaaronromeosfdctenharmsel_sftenharmsel_sfekozilforceekozilforcecoreypurcell_salesforcecoreypurcell_salesforcejmonrealjmonrealsconklinsconklinsuppadasuppadagnettergnettertkoh-sfdctkoh-sfdcjasoncummings-herokujasoncummings-herokudiana.doherty.sfdcdiana.doherty.sfdcjoeybrown90sfjoeybrown90sfrsoerensenrsoerensenademusoyoademusoyolsangalang2023lsangalang2023ccaseyccaseyryanbrainardryanbrainardmarcelsfdcmarcelsfdcnrisaronrisarochetankd10chetankd10kscareykscareybemory-herokubemory-herokurevativelagadarevativelagadabrock-salesforcebrock-salesforcebencdentonbencdentonrafaydinrafaydindhagberg-sfdhagberg-sfelzoonaelzoonacmarcojoscmarcojosadirasanamadirasanamkbaird-sfkbaird-sfbhawnaherokubhawnaherokujondaniel-sfdcjondaniel-sfdcgkomminenigkomminenip.shreyap.shreyasai_harshitha_neelasai_harshitha_neelaktsforcektsforcehkiihkiiheroku-front-endheroku-front-endvammundravammundrathe7okathe7okavlazukavlazukalucaszhoulucaszhoumarsmarsnlanattanlanattapranamsharmapranamsharmanrenkenrenkerichatiwaririchatiwaripsalimpsalimwchrisjohnsonwchrisjohnsonagatpareekagatpareekswapnilghoseswapnilghosemgates-salesforcemgates-salesforceryoneyamaryoneyamasripad.kulkarnisripad.kulkarnianujpandey001anujpandey001dboston528dboston528adirksmeieradirksmeierchristopher.josechristopher.josecbaxtersfcbaxtersfmttrmttrtetsuya_tetsuya_daebumleedaebumleemsaminenimsaminenisrishtigautamsrishtigautampbommapbommalalitreddylalitreddyzli-sfzli-sfsbaner18sbaner18joanneyeungjoanneyeungpaguilarpaguilarbleongbleongmontes_herokumontes_herokupfuentepfuentesaikrishna0202saikrishna0202jwadsworthsfjwadsworthsfjheikesjheikesmimenmimendaigo-herokudaigo-herokujmccartiejmccartiejordaneekeyjordaneekeylmckenzielmckenziev.anandv.anandarajaarajasarassassinsarassassinreidmixreidmixmbuschherokumbuschherokuk.plentyk.plentyeblackeblacksheax0rsheax0rk80bowmank80bowmanrdagg-herordagg-herogrundy.ggrundy.grobinson.mrobinson.mtcareysmith-sfdctcareysmith-sfdcptemporiniptemporinipaulaprado18paulaprado18harish.457harish.457jsullivandigsjsullivandigsntonollierntonollierelearyelearysalesforce-releasessalesforce-releases

Keywords

Readme

Test workflow status

sf-fx-runtime-nodejs

Building

$ npm ci && npm run build && npm link

Create a function using a template

  • Install the sfdx cli via npm
  • Install the functions plugin sfdx plugins:install @salesforce/plugin-functions
  • Generate a project and a function:
$ cd ~/
$ sfdx generate:project -n myproject
$ cd myproject
$ sfdx generate:function --language=javascript --name=nodejsfunction

Using

$ sf-fx-runtime-nodejs serve ~/myproject/functions/nodejsfunction

Invoke with fake data

$ ./invoke.sh "localhost:8080" "{}"

Invoke against a scratch org

Generate a scratch org using a dev hub:

$ sfdx plugins:install @salesforce/plugin-functions
$ cat > /tmp/project-scratch-def.json << EOF
{
  "orgName": "My company",
  "edition": "Developer",
  "features": ["EnableSetPasswordInApi"],
  "settings": {
    "lightningExperienceSettings": {
      "enableS1DesktopEnabled": true
    },
    "mobileSettings": {
      "enableS1EncryptedStoragePref2": false
    }
  }
}
EOF
$ sfdx force:auth:web:login -d -a MyHub
$ sfdx force:org:create -s -f /tmp/project-scratch-def.json -a MyScratchOrg

Verify the org was created correctly:

$ sfdx force:org:list --all | grep MyScratchOrg
(U)  MyScratchOrg  test-<uuid>@example.com  <SFDC ID> Active   2021-08-02

Invoke your local function with your scratch org:

$ sfdx run:function -l http://localhost:8080 -p '{}' -o MyScratchOrg

Release

Bumping versions

In order to bump a version, update the CHANGELOG.md and the package.json. You will also need to tag the release. Run the following script:

$ npm run bump -- $VERSION

Note: the format should be x.y.z-ext. There is no need to include the v in the version number.

Create a pull request with the created changes. The branch can be named release-vx.y.z. In the PR subject, name it Release vx.y.z with the version release.

Creating a release

Once the release's pull request is merged, update your local main branch.

Make sure you've got access to release the NPM package:

$ npm access ls-packages @heroku | grep sf-fx-runtime-nodejs
  "@heroku/sf-fx-runtime-nodejs": "read-write"

You'll be asked for your NPM two-factor authentication code when releasing. To release, run:

$ npm run release

The script will build the relase, push it up to S3, create a git tag, and push up the release to GitHub.

After the package has been pushed, you'll need to release a new version of the buildpack in github.com/heroku/buildpacks-nodejs.

Example Functions

This library supports functions using both JavaScript Modules / ESM AND CommonJS / Node modules. Salesforce functions is transitioning from CommonJS / Node modules to JavaScript Modules / ESM, where newer functions will use the latter, older functions the former. Examples of each follow.

JavaScript Modules / ESM

package.json

{
  "name": "nodejs-example-function",
  "version": "1.0.0",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "yahoo-stock-prices": "^1.1.0"
  }
}

index.js

import yahooStockPrices from "yahoo-stock-prices";

export default function (event, context, logger) => {
    logger.info("I'm logging stuff!");
    return yahooStockPrices.getCurrentData("CRM");
}

Node Modules / CommonJS

package.json

{
  "name": "nodejs-example-function",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "yahoo-stock-prices": "^1.1.0"
  }
}

index.js

const yahooStockPrices = require("yahoo-stock-prices");

module.exports = (event, context, logger) => {
    logger.info("I'm logging stuff!");
    return yahooStockPrices.getCurrentData("CRM");
}

Dev

Install Dependencies

$ npm install

Linting and Formatting

You can lint files with eslint like so:

$ npm run lint

We also use prettier to auto-format code. You can run that with

$ npm run format:fix

Tests

This will start our wiremock server and run the mocha tests:

$ npm run test

To run the mocha tests without booting wiremock (say you are running your own):

$ npm run mocha

Mocks

We use wiremock to provide a fake salesforce API during test and local dev.

Start the mock server with:

$ npm run wiremock

You can view mappings on disk at mappings/ and on the server (if it is running) at http://localhost:8080/__admin.

Recording new mocks

Get the URL of your salesforce scratch org:

$ sfdx force:org:display -u MyScratchOrg | grep "Instance Url"
Instance Url     https://<my-url>-dev-ed.cs45.my.salesforce.com/

following the wiremock docs on recording boot your wiremock server and navigate to http://localhost:8080/__admin/recorder. In the browser enter the URL of your salesforce scratch org. Using the above example it would be https://<my-url>-dev-ed.cs45.my.salesforce.com/

Now write your test as you normally would and point your url at your wiremock port (http://localhost:8080). Any requests made to this port will be forwarded to your salesforce url. The response will be recorded an a "scratch mapping" automatically generated.

When you've recorded a scratch mapping you want to use, rename it something descriptive before committing it. Also edit the mapping to remove the default "ignoreExtraElements": true declaration in bodyPatterns as it's been a source of issues where wiremock should have failed, but did not.

Tip: You can focus one specific test by passing the -g flag into mocha along with the name of the test. For example to run only the "invalid version" test you could run:

$ npm run mocha -- -g "invalid version"

> [email protected] test
> mocha "-g" "invalid version"



  DataApi Class
    create()
      invalid version
        ✓ throws a not found error


  1 passing (50ms)