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

@fairwords/abstraction-layer

v0.0.40

Published

API abstraction layer

Downloads

48

Readme

Abstraction Layer

The intermediary service between the application and api services.

Does two things:

  • Gets flagged terms from a detection Api
  • Gets Guide App settings from the Guide App api.

Getting Started

In your project install the package: npm i @fairwords/abstraction-layer

Configuration

Requires a configuration object with the AbstractorConfig interface:

The following properties for the config object:

gatewayCustomerId: string;         - Enterprise Id used in Guide app
gatewayEndpointHash: string;       - Endpoint Hash (name) used in the Guide app
gatewayApplicationHash: string;    - Application Hash (name) used in the Guide app
gatewayUserId?: string;            - UserId used in Guide app
detectionApiHttpEndpoint?: string; - Endpoint to a detection api http connection
detectionApiWsEndpoint?: string;   - Endpoint to a detection api websocket connection
httpPushAction?: string;           - Push action to a http connection ie. `POST`
httpFetchAction?: string;          - Fetch action to a http connection ie. `GET`
webSocketPushAction?: string;      - Push action to a websocket connection
webSocketFetchAction?: string;     - Fetch action to a websocket connection
kafkaBrokers: string;              - A list of brokers separated with ',' ie: localhost:9092,kafka.broker.com:9093
kafkaClientId: string;             - Kafka Client Id
kafkaGroupId: string;              - Kafka Group Id
kafkaSaslUsername: string;         - Sasl Username
kafkaSaslPassword: string;         - Sasl Password
kafkaTopics: string;               - A list of topics separated with ',' ie: policies,settings,users
offlineStatusTimoutMs: number      - Time until offline status in ms

Example Usage

import {
  AbstractorConfig,
  AbstractorService,
  BragiWebSocketTransport,
  BragiHttpTransport,
  KafkaConnector,
  KafkaTransport,
  HttpConnector,
  WebSocketConnector,
} from "@fairwords/abstraction-layer";
import { first } from "rxjs";

const config: AbstractorConfig = {
  gatewayCustomerId: process.env["GATEWAY_CUSTOMER_ID"],
  gatewayEndpointId: process.env["GATEWAY_ENDPOINT_ID"],
  gatewayApplicationId: process.env["GATEWAY_APPLICATION_ID"],
  detectionApiWsEndpoint: process.env["DETECTION_API_WS_ENDPOINT"],
  webSocketPushAction: "PUSH",
  webSocketFetchAction: "PULL",
  httpPushAction: "POST",
  httpFetchAction: "GET",
  kafkaBrokers: process.env["KAFKA_BROKERS"],
  kafkaClientId: process.env["KAFKA_CLIENT_ID"],
  kafkaGroupId: process.env["KAFKA_GROUP_ID"],
  kafkaSaslUsername: process.env["KAFKA_SASL_USERNAME"],
  kafkaSaslPassword: process.env["KAFKA_SASL_PASSWORD"],
  kafkaTopics: process.env["KAFKA_TOPICS"],
  offlineStatusTimoutMs: 10000,
};


// Bragi Websocket Setup
const bragiWebSocketTransport = new BragiWebSocketTransport(config);
const webSocketConnector = new WebSocketConnector(bragiWebSocketTransport, config);
const kafkaTransport = new KafkaTransport(config);
const kafkaConnector = new KafkaConnector(kafkaTransport);
const abstractorService = new AbstractorService(
  webSocketConnector,
  kafkaConnector
);

// or Bragi Http Setup
const bragiHttpTransport = new BragiHttpTransport(config);
const httpConnector = new HttpConnector(bragiHttpTransport, config);
const kafkaTransport = new KafkaTransport(config);
const kafkaConnector = new KafkaConnector(kafkaTransport);
const abstractorService = new AbstractorService(
  httpConnector,
  kafkaConnector
);

abstractorService.listen(ApiRole.Detector)?.subscribe((data) => {
  console.log(JSON.stringify(data));
});

abstractorService.push(ApiRole.Detector, {
  text: "text to evaluate",
  isTextFinal: false,
  additionalInfo: ["educationContent"],
} as AbstractorRequest);

abstractorService.sync().subscribe((data) => {
  console.log(data);
});