{"id":23380976,"url":"https://github.com/varun-verma-code/salesforce-streams-cds-nodejs","last_synced_at":"2025-04-08T08:19:09.613Z","repository":{"id":259316026,"uuid":"877560554","full_name":"varun-verma-code/salesforce-streams-cds-nodejs","owner":"varun-verma-code","description":"Service using Node and Express, that subscribes to Change Data Source events from Salesforce","archived":false,"fork":false,"pushed_at":"2024-12-09T22:49:57.000Z","size":1268,"stargazers_count":0,"open_issues_count":8,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-14T05:19:22.086Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/varun-verma-code.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-23T21:32:00.000Z","updated_at":"2024-10-23T21:43:30.000Z","dependencies_parsed_at":"2024-10-24T10:28:18.495Z","dependency_job_id":"666f3f13-18d7-4a9e-a416-f1f997671f5c","html_url":"https://github.com/varun-verma-code/salesforce-streams-cds-nodejs","commit_stats":null,"previous_names":["varunverma83/salesforce-streams-cds-nodejs","varun-verma-code/salesforce-streams-cds-nodejs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/varun-verma-code%2Fsalesforce-streams-cds-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/varun-verma-code%2Fsalesforce-streams-cds-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/varun-verma-code%2Fsalesforce-streams-cds-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/varun-verma-code%2Fsalesforce-streams-cds-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/varun-verma-code","download_url":"https://codeload.github.com/varun-verma-code/salesforce-streams-cds-nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801169,"owners_count":20998339,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-21T20:36:54.302Z","updated_at":"2025-04-08T08:19:09.586Z","avatar_url":"https://github.com/varun-verma-code.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# salesforce-streams-cds-nodejs\n\nService using Node and Express, that subscribes to Change Data Source events from Salesforce\n\n**This example app displays a feed of changes happening within a Salesforce org.**\n\n🤐🚫🙅‍♀️ _Do not connect this app with a production Salesforce org without proper security review. This app receives potentially confidental data from the Salesforce org via Streaming API._\n\n[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)\n\n![Screenshot of the web interface](doc/salesforce-activity-ui-v01.png)\n\n## Architecture\n\nThis app is composed of two server-side processes and a web UI:\n\n- [stream-consumer.js](stream-consumer.js), the Salesforce Streaming API consumer\n- [server.js](server.js), serves the web app and API feed of Account changes to web browsers\n- [pages/index.js](pages/index.js), the Next/React.js web UI\n\n![Diagram: reactive apps with Salesforce streaming](doc/salesforce-streams-nodejs-v03.png)\n\nMessages [flow](lib/subscribe-salesforce-streams.js#L108) from Salesforce into the stream consumer via [Bayeux/CometD](https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/BayeauxProtocolAndCometD.htm#!), and then are [pushed](stream-consumer.js#L35) into [Redis pub/sub](https://redis.io/topics/pubsub) so [requests](https://github.com/heroku-examples/salesforce-streams-nodejs/blob/master/server.js#L86) from each independent web client may [subscribe](pages/index.js#L156) to them via [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events).\n\nThe stream consumer is a single, single-threaded process to reliably ingest the ordered stream from Salesforce. Redis acts as a bridge to support scalable processing of the messages by multiple clients. In this example, we use Redis [`PUBLISH`/`SUBSCRIBE`](https://redis.io/topics/pubsub) to send every web client the complete stream. To instead provide a reliable queue of messages for scalable processing, pub/sub could be replaced with Redis [`LPUSH`/`RPOPLPUSH`/`LREM`](https://redis.io/commands/rpoplpush#pattern-reliable-queue).\n\nThis example app uses the [Change Data Capture (CDC)](https://developer.salesforce.com/docs/atlas.en-us.216.0.change_data_capture.meta/change_data_capture/cdc_intro.htm) stream for **Accounts**, which must be enabled for each desired object in Salesforce Setup:\n\n![Navigate to Salesforce Setup, then Integrations, then Change Data Capture](doc/Salesforce-setup-CDC.png \"Salesforce Setup: Change Data Capture\")\n\n## Local development\n\n### Requires\n\n- Salesforce\n  - [a free Developer Edition org](https://developer.salesforce.com/signup)\n- Heroku\n  - [a free account](https://signup.heroku.com)\n  - [command-line tools (CLI)](https://devcenter.heroku.com/articles/heroku-command-line)\n- [redis server](https://redis.io/download) (installed and listening on the default local port)\n- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)\n- [Node.js](https://nodejs.org) 10.x (**Make sure you have nvm installed to use Node v10.24.1**)\n\n### Setup\n\nIn your shell terminal, clone this repo to become the working directory:\n\n```bash\ngit clone https://github.com/heroku-examples/salesforce-streams-nodejs\ncd salesforce-streams-nodejs\n```\n\nInstall Node packages:\n\n```bash\nnpm install\n```\n\nCopy the local dev environment variables template, and then open `.env` in your editor:\n\n```\ncp .env.sample .env\n```\n\n✏️ _In `.env` [configure Salesforce authentication](#user-content-salesforce-authentication)._\n\n### Salesforce\n\nLogin to the Salesforce org.\n\nIn **Salesforce Setup** → **Integrations** → **Change Data Capture**, select which entities (objects) should produce change messages.\n\nFor this example app, **Account** is selected.\n\n### Running\n\nThe app is composed of two processes, declared in the [`Procfile`](Procfile). It may be start using the follow commands:\n\n```bash\nweb: node server.js\nstream_consumer: node stream-consumer.js\n```\n\n### Demo\n\n▶️ in a browser view the web UI [http://localhost:3000/](http://localhost:3000/).\n\n▶️ in a separate browser window, login to the associated Salesforce org. Create or update entities (example: Accounts) that are [configured](#user-content-salesforce) for CDC events.\n\n👀 observe the changes appearing in the web UI.\n\n⚡️☁ notice the bolt \u0026 cloud emojis in the web UI. The ⚡️ indicates the web browser's on-line status, while the ☁️ indicates the backend Salesforce streaming connection status. These indicators fade out when off-line. Hover over them to see a textual description of the current state.\n\n### Testing\n\nTested with [ava](https://github.com/avajs/ava):\n\n```bash\nnpm test\n```\n\n## Configuration\n\nConfigured via environment variables.\n\nFor local development, set these values in `.env` file.\n\nFor Heroku deployment, set these values via [Config Vars](https://devcenter.heroku.com/articles/config-vars).\n\n### Salesforce Authentication\n\n**required**\n\nAny one of the following authentication methods must be used by setting its variables:\n\n- Username + password\n  - `SALESFORCE_USERNAME`\n  - `SALESFORCE_PASSWORD` (the password and security token combined without spaces)\n  - `SALESFORCE_LOGIN_URL` (optional; defaults to **login.salesforce.com**)\n- Existing OAuth token\n  - `SALESFORCE_INSTANCE_URL`\n  - `SALESFORCE_ACCESS_TOKEN`\n  - Retrieve from an [sfdx](https://developer.salesforce.com/docs/atlas.en-us.212.0.sfdx_dev.meta/sfdx_dev/sfdx_dev_intro.htm) scratch org with `sfdx force:org:display`\n- OAuth client\n  - `SALESFORCE_URL`\n    - _Must include oAuth client ID, secret, \u0026 refresh token_\n    - Example: `force://{client-id}:{secret}:{refresh-token}@{instance-name}.salesforce.com`\n\n### Runtime Behavior\n\n- `FORCE_API_VERSION`\n  - Salesforce API version\n- `OBSERVE_SALESFORCE_TOPIC_NAMES`\n  - **required**\n  - the path part of a Streaming API URL\n  - a comma-delimited list\n  - example: `OBSERVE_SALESFORCE_TOPIC_NAMES=/event/Heroku_Function_Generate_UUID_Invoke__e`\n- `REDIS_URL`\n  - **required**\n  - connection config to Redis datastore\n  - example: `REDIS_URL=redis://localhost:6379`\n  - default: should be set from Heroku Redis add-on\n- `REPLAY_ID`\n  - force a specific replayId for Salesforce Streaming API\n  - ensure to unset this after usage to prevent the stream from sticking\n  - example: `REPLAY_ID=5678` (or `-2` for all possible events)\n  - default: unset, receive all new events\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvarun-verma-code%2Fsalesforce-streams-cds-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvarun-verma-code%2Fsalesforce-streams-cds-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvarun-verma-code%2Fsalesforce-streams-cds-nodejs/lists"}