@mdf.js/openc2-core
Version:
MMS - API Core - OpenC2
93 lines • 3.53 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, Links, Multi } from '@mdf.js/crash';
import { LoggerInstance } from '@mdf.js/logger';
import EventEmitter from 'events';
import express from 'express';
import { Router } from '../Router';
import { HealthWrapper, Registry } from '../modules';
import { ComponentAdapter, ComponentOptions } from '../types';
export declare interface Component<T, K> {
/**
* Add a listener for the `error` event, emitted when the component detects an error.
* @param event - `error` event
* @param listener - Error event listener
* @event
*/
on(event: 'error', listener: (error: Crash | Multi | Error) => void): this;
/**
* Add a listener for the status event, emitted when the component status changes.
* @param event - `status` event
* @param listener - Status event listener
* @event
*/
on(event: 'status', listener: (status: Health.Status) => void): this;
}
export declare abstract class Component<T extends ComponentAdapter, K extends ComponentOptions> extends EventEmitter implements Layer.App.Service {
protected readonly adapter: T;
protected options: K;
/** Component identification */
readonly componentId: string;
/** Component commands and message register */
protected readonly register: Registry;
/** Registry router */
protected readonly _router: Router;
/** Logger instance */
protected readonly logger: LoggerInstance;
/** Health wrapper instance */
protected readonly health: HealthWrapper;
/** Component started flag */
private started;
/**
* Abstract OpenC2 component implementation.
* @param adapter - transport adapter
* @param options - configuration options
*/
constructor(adapter: T, options: K);
/** Component name */
get name(): string;
/** Component health status */
get status(): Health.Status;
/**
* Return the status of the Consumer 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;
/** Return an Express router with access to OpenC2 information */
get router(): express.Router;
/** Return links offered by this service */
get links(): Links;
/**
* Manage the error in the producer interface
* @param error - error to be processed
*/
protected readonly onErrorHandler: (error: unknown) => void;
/**
* Manage the status change in the producer interface
* @param status - status to be processed
*/
private readonly onStatusHandler;
/**
* Connect the OpenC2 Adapter to the underlayer transport system and perform the startup of the
* component
*/
start(): Promise<void>;
/**
* Disconnect the OpenC2 Adapter to the underlayer transport system and perform the shutdown of
* the component
*/
stop(): Promise<void>;
/** Close the OpenC2 component */
close(): Promise<void>;
/** Initialize the OpenC2 component */
protected abstract startup(): Promise<void>;
/** Shutdown the OpenC2 component */
protected abstract shutdown(): Promise<void>;
}
//# sourceMappingURL=Component.d.ts.map