A simple TypeScript application that:
- uses the nforce library to connect and authorize to a Salesforce org
- uses the faye library to connect to the Salesforce Streaming API and subscribe to the CommerceDiagnosticEvent platform event
- serves a webpage that dynamically displays the received CommerceDiagnosticEvents as they are emitted
- Make sure you have an active B2B Commerce webstore
- In your org, create a connected app: https://help.salesforce.com/articleView?id=connected_app_create.htm
- Make sure to follow the steps for OAuth 2.0 authentication in the section
Enable OAuth Settings for API Integration
- OAuth should point to this app's URL like so
http://localhost:5000/oauth/_callback
orhttps://app-name.herokuapp.com/oauth/_callback
- Create a heroku account at https://heroku.com (only necessary if hosting on heroku)
- Get the CLI: https://devcenter.heroku.com/articles/heroku-cli
- SF_CLIENT_ID, enter the Consumer Key of your Salesforce Connected App
- SF_CLIENT_SECRET, enter the Consumer Secret of your Salesforce Connected App
- SF_USER_NAME, enter the the username of your Salesforce user
- SF_USER_PASSWORD, enter the the password of your Salesforce user
- (OPTIONAL) SF_LOGIN_SRV, enter the login server name (optional, defaults to
login.salesforce.com
, if you want sandbox set this totest.salesforce.com
) - (OPTIONAL) REDIRECT_URL to the URL of the app itself (optional, defaults to
https://app-name.herokuapp.com/oauth/_callback
)
- Run
npm install
to get dependencies - Run
npm run build
to compile TypeScript files - Copy
.env.tmpl
to.env
- Edit
.env
and set the configuration values (see above). Set REDIRECT_URL tohttp://localhost:5000/oauth/_callback
- Start the app:
heroku local
- Run these commands (do not fill in the config values)
heroku apps:create <your-app-name>
heroku labs:enable runtime-dyno-metadata
heroku config:set SF_CLIENT_ID=foo SF_CLIENT_SECRET=bar [email protected] SF_USER_PASSWORD=xyz
- Go to the settings page on heroku for your app, and update the configuration settings for SF_CLIENT_ID, etc..
- Now run:
git push heroku master
heroku open
Code is based on these two repos: