Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vendease-common

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vendease-common

contains a set of common utility functions, classes, and modules that are used across the Vendease platform's backend system

  • 2.1.17
  • npm
  • Socket score

Version published
Weekly downloads
12
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

vendease backend common

contains a set of common utility functions, classes, and modules that are used across the Vendease platform's backend system

Code example Jetstream setup

const CONFIG = {
  connectionOptions: {
    servers: ["localhost"],
    name: process.env.APP_NAME ?? "e-procurement",
  },
  consumerOptions: {
    deliverGroup: process.env.JETSTREAM_DELIVER_GROUP ?? "core-service-group",
    durable: process.env.JETSTREAM_CONSUMER_DURABLE ?? "core-services-durable",
    deliverTo: process.env.JETSTREAM_CONSUMER_DELIVER_TO ?? "core-services-deliver-to",
    manualAck: Boolean(process.env.JETSTREAM_MANUAL_ACK ?? "true"),
  },
  streamConfig: {
    name: process.env.JETSTREAM_STREAM_NAME || "core-services",
    subjects: (process.env.JETSTREAM_STREAM_SUBJECTS || "core.*").split(","),
  },

  //   host: process.env.NATS_HOST || 'demo.nats.io',
  //   port: Number(process.env.NATS_PORT) || 4222,
};
interface ICreateCompany {
  subject: Subjects.CompanyCreated;
  data: { id: number; name: string };
}
interface IUserCreatedCompany {
  subject: Subjects.UserCreated;
  data: { id: number; first_name: string; last_name: string };
}

// Singleton
class SingleInstanceStream extends BaseStream {
  queueGroupName: string = "sample group";

  protected async onMessage(data: any, msg: JsMsg): Promise<void> {
    console.log(data);
    console.log(msg.subject);

    switch (msg.subject) {
      case "Subjects.UserCreated":
        return this.handleUserCreated(data);
      case Subjects.CompanyCreated:
        return this.handleCompanyCreated(data);
      default:
        return "i probably don't understand this message";
    }

    msg.ack();
  }
}

export async function testConnection() {
  const stream = new SingleInstanceStream(config);

  await stream.connect();

  await stream.publish<IUserCreatedCompany>(Subjects.UserCreated, { id: 20, first_name: "bola", last_name: "tinubu" });
  await stream.publish<ICreateCompany>(Subjects.CompanyCreated, { id: 20, name: "dayo's company company created" });

  await stream.listen();

  await stream.close();
}

FAQs

Package last updated on 21 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc