UNPKG

@isaac-platform/isaac-integration-sdk

Version:

A Typescript SDK for integrating with ISAAC

70 lines (69 loc) 2.2 kB
import EventEmitter from "events"; import * as util from "util"; import isaacConnection from "../../controller/isaac.js"; export class IsaacEvent extends EventEmitter { constructor(definition) { super(); this.definition = definition; this.subsystemExternalId = definition.subsystemExternalId; } get() { return this; } // Get/Set - command property get command() { return this.definition.command || "undefined"; } set command(value) { this.definition.command = value; this.update({ command: value }); } // Get/Set - description property get description() { return this.definition.description || "undefined"; } set description(value) { this.definition.description = value; this.update({ description: value }); } // Get/Set - displayName property get displayName() { return this.definition.displayName || "undefined"; } set displayName(value) { this.definition.displayName = value; this.update({ displayName: value }); } // Get/Set - availableInSubsystem property get availableInSubsystem() { return this.definition.availableInSubsystem || false; } set availableInSubsystem(value) { this.definition.availableInSubsystem = value; this.update({ availableInSubsystem: value }); } toggleAvailability() { this.availableInSubsystem = !this.availableInSubsystem; } // Get/Set - metadata property get metadata() { return this.definition.metadata || {}; } set metadata(value) { this.definition.metadata = value; this.update({ metadata: value }); } update(updateParameters) { try { isaacConnection.putRequest(`events/${this.definition._id}`, updateParameters); } catch (error) { console.error('ISAAC SDK: Error updating event.', error); throw error; } } // Override inspect behavior for logging. [util.inspect.custom](depth, opts) { return `${this.subsystemExternalId || this.subsystemId} - ${this.displayName || this.externalRef}`; } }