@mdf.js/openc2
Version:
MMS - API - Observability
86 lines • 3.25 kB
TypeScript
/**
* Copyright 2024 Mytra Control S.L. All rights reserved.
*
* Use of this source code is governed by an MIT-style license that can be found in the LICENSE file
* or at https://opensource.org/licenses/MIT.
*/
import { Health, Layer } from '@mdf.js/core';
import { Crash } from '@mdf.js/crash';
import EventEmitter from 'events';
import { SocketIOServerOptions } from '../types';
export declare interface ServiceBus {
/** Emitted when a server operation has some problem */
on(event: 'error', listener: (error: Crash | Error) => void): this;
/** Emitted on every state change */
on(event: 'status', listener: (status: Health.Status) => void): this;
}
export interface ServiceBusOptions {
/** Define the use of JWT tokens for client authentication */
useJwt?: boolean;
/** Secret used in JWT token validation */
secret?: string;
}
export declare class ServiceBus extends EventEmitter implements Layer.App.Resource {
readonly name: string;
/** Component identification */
readonly componentId: string;
/** Socket.IO server instance */
private readonly instance;
/** OpenC2 Namespace */
private readonly oc2Namespace;
/** Address mapper */
private readonly addressMapper;
/**
* Create a new ServiceBus instance
* @param serverOptions - Socket.IO server options
* @param options - Socket.IO client configuration options
* @param name - name of the service bus
*/
constructor(serverOptions: SocketIOServerOptions, options: ServiceBusOptions, name: string);
/**
* Connection event handler for the OpenC2 namespace
* @param socket - socket to be configured
*/
private readonly onConnectionEventOC2Namespace;
/**
* Manage the incoming commands events from provider
* @param event - event name
* @param command - command message from provider
* @param callback - callback function, used as acknowledgement
*/
private readonly eventHandler;
/** Socket disconnection handler */
private readonly onDisconnectEvent;
/**
* Transforms the disconnection reason in a Crash if its an unmanaged reason
* @param reason - reason for the error
* @param openC2Id - openC2 identification
* @returns
*/
private disconnectReasonToCrashError;
/**
* Manage the error in the service bus
* @param error - error to be processed
*/
private readonly onErrorHandler;
/**
* Manage the status change in the service bus
* @param status - status to be processed
*/
private readonly onStatusHandler;
/** Start the underlayer Socket.IO server */
start(): Promise<void>;
/** Close the server and disconnect all the actual connections */
stop(): Promise<void>;
/** Close the server and disconnect all the actual connections */
close(): Promise<void>;
/** Return the status of the server */
get status(): Health.Status;
/**
* Return the status of the server in a standard format
* @returns _check object_ as defined in the draft standard
* https://datatracker.ietf.org/doc/html/draft-inadarei-api-health-check-05
*/
get checks(): Health.Checks;
}
//# sourceMappingURL=ServiceBus.d.ts.map