This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

platform-event-stream

1.0.1 • Public • Published

Platform Event Stream

npm license

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 Logger
    • info: Required, implementation for the logger.info() method.
    • error: Required, implementation for the logger.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
});

License

MIT

Package Sidebar

Install

npm i platform-event-stream

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

6.67 kB

Total Files

6

Last publish

Collaborators

  • adtennant