platform-event-stream v1.0.1
Platform Event Stream
A small library that converts Salesforce Platform Events converted into a Readable Stream in Object Mode.
const through2 = require('through2');
const platformEventStream = require('platform-event-stream');
const jsonStream = through2.obj(function(chunk, encoding, callback) {
this.push(JSON.stringify(chunk, null, 4) + '\n')
callback()
});
platformEventStream({
connection: {
clientId: 'OAUTH_CLIENT_ID',
clientSecret: 'OAUTH_CLIENT_SECRET',
redirectUri: 'http://localhost:3000/oauth/_callback'
},
authentication: {
username: 'user@example.com',
password: 'password',
securityToken: 'securityToken',
},
eventName: 'Event__e',
logger: console
})
.pipe(jsonStream)
.pipe(process.stdout);
Event__e
events will be piped to stdout
(usually the console) as they are published from Salesforce.
Installation
npm:
npm install platform-event-stream
Yarn:
yarn add platform-event-stream
Usage
platformEventStream(connection, authentication, options)
Creates a Readable Stream in Object Mode for the eventName
defined in options
.
options
connection
: Required, see, see notes below.authentication
: Required, see notes below.eventName
: Required, the API name of the Platform Event to subscribe to, e.g.Event__e
logger
: Optional, a custom logger. See: Custom Loggerinfo
: Required, implementation for thelogger.info()
method.error
: Required, implementation for thelogger.error()
method.
Details of the Org to connect to are provided in connection
, and authentication details provided in authentication
. As Platform Event Stream uses nforce
internally, these objects use the same format as those provided to nforce
's createConnection
and authenticate
methods respectively.
Custom Logger
A custom logger object can be provided to output details about the stream and any errors that occur.
The logger object has the following interface:
{
info: (object [, object, ...]) => void,
error: (object [, object, ...]) => void
}
The simple interface is designed so that you can pass most logging libraries (e.g. bunyan, winston) or console
directly, alternatively you can implement your own.
const myLogger = {
info: (...args) => (), // Don't bother outputting info messages
error: (...args) => console.error(args),
}
platformEventStream({
...
logger: myLogger,
// logger: console
});