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

@gus-eip/platform-listener

v1.8.5

Published

@gus-eip/platform-listener is a package designed to provide platform event listening functionality for your Node.js applications.

Downloads

574

Readme

@gus-eip/platform-listener

@gus-eip/platform-listener is a NestJS service for subscribing to Salesforce platform events using the CometD protocol. It handles authentication with Salesforce, establishes a connection to the CometD server, and provides an observable stream of received events.

Installation

To install this package, use npm:

npm install @gus-eip/platform-listener rxjs

Usage

Import the Module

First, you need to import the PlatformEventService into your NestJS module.

import { Module } from '@nestjs/common';
import { PlatformEventService } from '@gus-eip/platform-listener';

@Module({
  providers: [PlatformEventService],
  exports: [PlatformEventService],
})
export class AppModule {}

Inject the Service

Inject the PlatformEventService into your controller or another service where you want to consume the events.

import { Controller, OnModuleInit } from '@nestjs/common';
import { PlatformEventService } from '@gus-eip/platform-listener';

@Controller()
export class AppController implements OnModuleInit {
  constructor(private readonly platformEventService: PlatformEventService) {}

  async onModuleInit() {
    // Initialize the platform listener
    await this.platformEventService.platformListener('YourPlatformEventName');

    // Subscribe to the event stream
    this.platformEventService.getEventStream().subscribe((message) => {
      console.log('Received event:', message);
      // Process the event here
    });
  }
}

Configuration

When creating an instance of the PlatformEventService, you need to provide the necessary Salesforce credentials and configuration details.

import { PlatformEventService } from '@gus-eip/platform-listener';

const platformEventService = new PlatformEventService(
  'your-username',
  'your-password',
  'your-client-id',
  'your-client-secret',
  'your-auth-url',
  'your-event-table'
);

Example

Here's a full example:

AppModule

import { Module } from '@nestjs/common';
import { PlatformEventService } from '@gus-eip/platform-listener';
import { AppController } from './app.controller';

@Module({
  providers: [
    {
      provide: PlatformEventService,
      useFactory: () => {
        return new PlatformEventService(
          'your-username',
          'your-password',
          'your-client-id',
          'your-client-secret',
          'your-auth-url',
          'your-event-table'
        );
      },
    },
  ],
  controllers: [AppController],
  exports: [PlatformEventService],
})
export class AppModule {}

AppController

import { Controller, OnModuleInit } from '@nestjs/common';
import { PlatformEventService } from '@gus-eip/platform-listener';

@Controller()
export class AppController implements OnModuleInit {
  constructor(private readonly platformEventService: PlatformEventService) {}

  async onModuleInit() {
    await this.platformEventService.platformListener('YourPlatformEventName');

    this.platformEventService.getEventStream().subscribe((message) => {
      console.log('Received event:', message);
      // Process the event here
    });
  }
}

API

platformListener(platformEventName: string): Promise<void>

Initializes the platform event listener for the specified event name.

  • platformEventName: The name of the Salesforce platform event to subscribe to.

getEventStream()

Returns an observable stream of received events. Other parts of the application can subscribe to this observable to receive real-time updates.

License

MIT


This `README.md` file provides a clear guide on how to install, configure, and use the `@gus-eip/platform-listener` package in a NestJS application. It includes detailed instructions, example code, and API documentation.