UNPKG

@mdf.js/openc2-core

Version:

MMS - API Core - OpenC2

73 lines 3.19 kB
/** * 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 { RetryOptions } from '@mdf.js/utils'; import EventEmitter from 'events'; import { ConsumerAdapter, OnCommandHandler } from '../../../types'; export declare class AdapterWrapper extends EventEmitter implements Layer.App.Resource { private readonly adapter; /** Operation retry options */ private readonly retryOptions; /** Flag to indicate that an unhealthy status has been emitted recently */ private lastStatusEmitted?; /** Indicate if the last operation was finished with error */ private lastOperationError?; /** Date of the last operation performed */ private lastOperationDate?; /** Subscribe the incoming message handler to the underlayer transport system */ private readonly subscribeOriginal; /** Unsubscribe the incoming message handler from the underlayer transport system */ private readonly unsubscribeOriginal; /** * Create a new instance of AdapterWrapper * @param adapter - adapter instance * @param retryOptions - options for job retry operations */ constructor(adapter: ConsumerAdapter, retryOptions?: RetryOptions); /** Component name */ get name(): string; /** Component identifier */ get componentId(): string; /** Connect the OpenC2 Adapter to the underlayer transport system */ start(): Promise<void>; /** Disconnect the OpenC2 Adapter to the underlayer transport system */ stop(): Promise<void>; /** Close the OpenC2 Adapter to the underlayer transport system */ close(): Promise<void>; /** * Check if the adapter implements the mandatory methods * @throws Crash if the adapter does not implement the mandatory methods */ private checkMandatoryMethods; /** * Perform the retry functionality for a promise * @param task - promise to execute * @param funcArgs - promise arguments * @param options - control execution options * @returns */ private wrappedOperation; /** Overall component status */ get status(): Health.Status; /** Emit the status if it's different from the last emitted status */ private emitStatus; /** Register an error in the adapter operation */ private readonly onOperationError; /** Register an error in the adapter operation */ private readonly onOperationSuccess; /** Subscribe the incoming message handler to the underlayer transport system */ subscribe: (handler: OnCommandHandler) => Promise<void>; /** Unsubscribe the incoming message handler from the underlayer transport system*/ unsubscribe: (handler: OnCommandHandler) => Promise<void>; /** * Return the status of the adapter 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=AdapterWrapper.d.ts.map