@fairwords/abstraction-layer
v0.0.40
Published
API abstraction layer
Downloads
12
Maintainers
Keywords
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);
});