0.0.40 • Published 1 year ago

@fairwords/abstraction-layer v0.0.40

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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);
});
0.0.40

1 year ago

0.0.37

1 year ago

0.0.38

1 year ago

0.0.39

1 year ago

0.0.36

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.33

2 years ago

0.0.34

2 years ago

0.0.35

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago