Options
All
  • Public
  • Public/Protected
  • All
Menu

TypeScript ACAEngine Library

This library is a Typescript interface to ACAEngine

Compilation

You can build the library from source after installing the dependencies with the command

npm run build

Usage

API docs can be found here

You can install the ACAEngine Typescript client with the npm command

npm install --save-dev @acaengine/ts-client

After the package is installed you can import ACAEngine into your application

import { ACAEngine } from '@acaengine/ts-client'

Before using ACAEngine it will need to be intialised.

ACAEngine.init(config);

The init method takes a config object with the following properties

Property Description Optional Type Example
host Host name and port of the ACAEngine server Yes string "dev.acaengine.com:8080"
mock Whether to initialise ACAEngine with mock services Yes boolean true
auth_uri URI for authorising users session No string "/auth/oauth/authorize"
token_uri URI for generating new auth tokens No string "/auth/token"
redirect_uri URI to redirect user to after authorising session No string "/oauth-resp.html"
scope Scope of the user permissions needed by the application No string "admin"
storage Browser storage to use for storing user credentials Yes "local" | "session"
handle_login Whether ACAEngine should handle user login Yes boolean true

Once initialised the ACAEngine object will expose interfaces to ACAEngine's websocket and http APIs

Websocket API

ACAEngine exposes a websocket API through the bindings service.

The bindings service is used to provide real-time interaction with modules running on ACAEngine. It provides an interface to build efficient, responsive user interfaces, monitoring systems and other extensions which require live, two-way or asynchronous interaction.

Once ACAEngine has initialised you can listen to values on modules

const my_mod = ACAEngine.bindings.module('sys-death-star', 'TestModule', 3);
const my_variable = my_mod.binding('power');
const unbind = my_variable.bind();
const sub = my_variable.listen((value) => doSomething(value));

This binds to the power status variable on the 3rd TestModule in the system sys-death-star. Any changes to the value of power on ACAEngine will then be emitted to the function passed to listen.

Other than listening to changes of values you can also remotely execute methods on modules.

const my_mod = ACAEngine.bindings.module('sys-death-star', 'DemoModule', 2);
my_mod.exec('power_off').then(
    (resp) => handleSuccess(resp)
    (err) => handleError(err)
);

This will execute the method power_off on the 2nd DemoModule in the system sys-death-star. If the method doesn't exist or the system is turned off it will return an error. The response from ACAEngine can be handled using the promise returned by the exec method.

HTTP API

For the HTTP API, ACAEngine provides a service for each of the root endpoints available on ACAEngine's RESTful API.

Docs for the API can be found here https://docs.acaengine.com/api/control

Services are provided for drivers, modules, systems, users, and zones

Each service except for users provides CRUD methods. users provides _RUD.

// Drivers CRUD
ACAEngine.drivers.add(driver_data).then((new_driver) => doSomething(new_driver));
ACAEngine.drivers.show(driver_id).then((driver) => doSomething(driver));
ACAEngine.drivers.update(driver_id, driver_data).then((updated_driver) => doSomething(updated_driver));
ACAEngine.drivers.delete(driver_id).then(() => doSomething());

// Modules CRUD
ACAEngine.modules.add(module_data).then((new_module) => doSomething(new_module));
ACAEngine.modules.show(module_id).then((mod) => doSomething(mod));
ACAEngine.modules.update(module_id, module_data).then((updated_module) => doSomething(updated_module));
ACAEngine.modules.delete(module_id).then(() => doSomething());

// Systems CRUD
ACAEngine.systems.add(system_data).then((new_system) => doSomething(new_system));
ACAEngine.systems.show(system_id).then((system) => doSomething(system));
ACAEngine.systems.update(system_id, system_data).then((updated_system) => doSomething(updated_system));
ACAEngine.systems.delete(system_id).then(() => doSomething());

// Users CRUD
ACAEngine.users.add(user_data).then((new_user) => doSomething(new_user)); // This will error
ACAEngine.users.show(user_id).then((user) => doSomething(user));
ACAEngine.users.update(user_id, user_data).then((updated_user) => doSomething(updated_user));
ACAEngine.users.delete(user_id).then(() => doSomething());

// Zones CRUD
ACAEngine.zones.add(zone_data).then((new_zone) => doSomething(new_zone));
ACAEngine.zones.show(zone_id).then((zone) => doSomething(zone));
ACAEngine.zones.update(zone_id, zone_data).then((updated_zone) => doSomething(updated_zone));
ACAEngine.zones.delete(zone_id).then(() => doSomething());

The services also provide methods for the various item action endpoints

// Driver Actions
ACAEngine.drivers.reload(driver_id);

// Module Actions
ACAEngine.module.start(module_id);
ACAEngine.module.stop(module_id);
ACAEngine.module.ping(module_id);
ACAEngine.module.lookup(module_id, lookup);
ACAEngine.module.internalState(module_id);

// System Actions
ACAEngine.system.remove(system_id, module_name);
ACAEngine.system.start(system_id);
ACAEngine.system.stop(system_id);
ACAEngine.system.execute(system_id, module_name, index, args);
ACAEngine.system.state(system_id, module_name, index, lookup);
ACAEngine.system.functionList(system_id, module_name, index);
ACAEngine.system.types(system_id, module_name);
ACAEngine.system.count(system_id);

// User Actions
ACAEngine.users.current();

Objects returned by show and query methods are immutable, though when reassigning value it will be saved under the changes property of that object. These changes can be saved using the save method which will return a promise for the new object.

ACAEngine.zones.show(zone_id).then((zone) => {
    console.log(zone.description); // Prints the current description
    zone.description = 'New description';
    console.log(zone.description); // Same a previous print
    cosnole.log(zone.changes.description) // New description
    zone.save().then((updated_zone) => {
        cosnole.log(updated_zone.description) // New description
    });
});

You can find more details about endpoint action on the API docs

https://app.swaggerhub.com/apis/ACAprojects/ACAEngine/3.5.0#/

Writing mocks

If you don't have access to an ACAEngine server you can also write mocks so that you can still develop interfaces for ACAEngine.

To use the mock services you can pass mock: true into the initialisation object.

Websockets

To write mocks for the the realtime(websocket) API you'll need to add your systems to window.control.systems before initialising ACAEngine.

window.control.systems = {
    "my-system": {
        "MyModule": [
            {
                power: true,
                $power_on: function () { this.power = true },
                $power_off: function () { this.power = false }
            }
        ]
    }
}

Note that executable methods on mock systems are namespaced with $ as real systems in engine allow for methods to have the same name as variables.

Once initialised interactions with a system are performed in the same manner as the live system.

const my_mod = ACAEngine.bindings.module('my-system', 'MyModule', 1);
const my_variable = my_mod.binding('power');
const unbind = my_variable.bind();
const sub = my_variable.listen((value) => doSomething(value)); // Emits true
my_mod.exec('power_off'); // The listen callback will now emit false

Some methods may need access to other modules within the system, for this a property is appended on runtime called _system which allows for access to the parent system

window.control.systems = {
    "my-system": {
        "MyModule": [
            {
                $lights_off: function () { this._system.MyOtherModule[0].lights = false; }
            }
        ]
        "MyOtherModule": [
            {
                lights: true,
            }
        ]
    }
}

HTTP Requests

HTTP API Requests can be mocked in a similar way to the realtime API by adding handlers to window.control.handlers

window.control.handlers = [
    {
        path: '/api/engine/v2/systems',
        metadata: {},
        method: 'GET',
        callback: (request) => my_mock_systems
    }
]

Paths allow for route parameters and will pass the value in the callback input.

window.control.handlers = [
    {
        path: '/api/engine/v2/systems/:system_id',
        ...
        callback: (request) =>
            my_mock_systems.find(sys => sys.id === request.route_params.system_id)
    }
]

Query parameters are also available on the callback input.

GET, POST, PUT, PATCH and DELETE requests can be mocked out.

If a request is made and there are no handlers it will attempt to make the live request.

Index

Modules

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

Object literals

Type aliases

ApplicationMutableFields

ApplicationMutableFields: ApplicationMutableTuple[number]

ApplicationMutableTuple

ApplicationMutableTuple: typeof APPLICATION_MUTABLE_FIELDS

BaseMutableFields

BaseMutableFields: BaseMutableTuple[number]

BaseMutableTuple

BaseMutableTuple: typeof BASE_MUTABLE_FIELDS

DomainMutableFields

DomainMutableFields: DomainMutableTuple[number]

DomainMutableTuple

DomainMutableTuple: typeof DOMAIN_MUTABLE_FIELDS

DriverMutableFields

DriverMutableFields: DriverMutableTuple[number]

DriverMutableTuple

DriverMutableTuple: typeof DRIVER_MUTABLE_FIELDS

EndDebugFn

EndDebugFn: () => void

Function to request the server to stop emitting debug events

Type declaration

    • (): void
    • Returns void

EngineCommand

EngineCommand: "bind" | "unbind" | "debug" | "ignore" | "exec"

EngineDataEventType

EngineDataEventType: "value_change" | "item_saved" | "reset" | "other"

HttpResponse

HttpResponse: HashMap | string | void

HttpResponseType

HttpResponseType: "json" | "text" | "void"

HttpVerb

HttpVerb: "GET" | "POST" | "PUT" | "PATCH" | "DELETE"

HTTP request verb. Can be one of either GET, POST, PUT, PATCH, or DELETE

LdapSourceMutableFields

LdapSourceMutableFields: LdapSourceMutableTuple[number]

LdapSourceMutableTuple

LdapSourceMutableTuple: typeof LDAP_SOURCE_MUTABLE_FIELDS

ModuleMutableFields

ModuleMutableFields: ModuleMutableTuple[number]

ModuleMutableTuple

ModuleMutableTuple: typeof MODULE_MUTABLE_FIELDS

OAuthSourceMutableFields

OAuthSourceMutableFields: OAuthSourceMutableTuple[number]

OAuthSourceMutableTuple

OAuthSourceMutableTuple: typeof OAUTH_SOURCE_MUTABLE_FIELDS

RepositoryMutableFields

RepositoryMutableFields: RepositoryMutableTuple[number]

RepositoryMutableTuple

RepositoryMutableTuple: typeof REPOSITORY_MUTABLE_FIELDS

SamlSourceMutableFields

SamlSourceMutableFields: SamlSourceMutableTuple[number]

SamlSourceMutableTuple

SamlSourceMutableTuple: typeof SAML_SOURCE_MUTABLE_FIELDS

SettingsMutableFields

SettingsMutableFields: SettingsMutableTuple[number]

SettingsMutableTuple

SettingsMutableTuple: typeof SETTINGS_MUTABLE_FIELDS

SystemMutableFields

SystemMutableFields: SystemMutableTuple[number]

SystemMutableTuple

SystemMutableTuple: typeof SYSTEM_MUTABLE_FIELDS

TriggerConditionConstant

TriggerConditionConstant: number | string | boolean

TriggerConditionValue

TriggerMutableFields

TriggerMutableFields: TriggerMutableTuple[number]

TriggerMutableTuple

TriggerMutableTuple: typeof TRIGGER_MUTABLE_FIELDS

TriggerTimeCondition

UserMutableFields

UserMutableFields: UserMutableTuple[number]

UserMutableTuple

UserMutableTuple: typeof USER_MUTABLE_FIELDS

ZoneMutableFields

ZoneMutableFields: ZoneMutableTuple[number]

ZoneMutableTuple

ZoneMutableTuple: typeof ZONE_MUTABLE_FIELDS

Variables

Const APPLICATION_MUTABLE_FIELDS

APPLICATION_MUTABLE_FIELDS: ["name", "owner_id", "scopes", "redirect_uri", "skip_authorization"] = ['name','owner_id','scopes','redirect_uri','skip_authorization'] as const

Const BASE_MUTABLE_FIELDS

BASE_MUTABLE_FIELDS: ["name"] = ['name'] as const

Const DOMAIN_MUTABLE_FIELDS

DOMAIN_MUTABLE_FIELDS: ["name", "dom", "login_url", "logout_url", "description", "config", "internals"] = ['name', 'dom', 'login_url', 'logout_url', 'description', 'config', 'internals'] as const

Const DRIVER_MUTABLE_FIELDS

DRIVER_MUTABLE_FIELDS: ["name", "description", "module_name", "role", "default", "ignore_connected", "repository_id", "file_name", "commit"] = ['name','description','module_name','role','default','ignore_connected','repository_id','file_name','commit'] as const

Const KEEP_ALIVE

KEEP_ALIVE: 20 = 20

Time in seconds to ping the server to keep the websocket connection alive

Const LDAP_SOURCE_MUTABLE_FIELDS

LDAP_SOURCE_MUTABLE_FIELDS: ["name", "authority_id", "host", "port", "auth_method", "uid", "base", "bind_dn", "password", "filter"] = ['name','authority_id','host','port','auth_method','uid','base','bind_dn','password','filter'] as const

Const MODULE_MUTABLE_FIELDS

MODULE_MUTABLE_FIELDS: ["name", "dependency_id", "control_system_id", "ip", "tls", "udp", "port", "makebreak", "uri", "custom_name", "role", "notes", "ignore_connected"] = ['name','dependency_id','control_system_id','ip','tls','udp','port','makebreak','uri','custom_name','role','notes','ignore_connected'] as const

Const NON_EDITABLE_FIELDS

NON_EDITABLE_FIELDS: string[] = ['authority_id']

List of property keys that can only be set when creating a new object List of property keys that can only be set when creating a new object List of property keys that can only be set when creating a new object List of property keys that can only be set when creating a new object List of property keys that can only be set when creating a new object List of property keys that can only be set when creating a new object List of property keys that can only be set when creating a new object List of property keys that can only be set when creating a new object

Const OAUTH_SOURCE_MUTABLE_FIELDS

OAUTH_SOURCE_MUTABLE_FIELDS: ["name", "authority_id", "client_id", "client_secret", "info_mappings", "site", "authorize_url", "token_method", "token_url", "auth_scheme", "scope", "raw_info_url"] = ['name','authority_id','client_id','client_secret','info_mappings','site','authorize_url','token_method','token_url','auth_scheme','scope','raw_info_url'] as const

Const REPOSITORY_MUTABLE_FIELDS

REPOSITORY_MUTABLE_FIELDS: ["name", "folder_name", "description", "uri", "commit_hash", "type"] = ['name', 'folder_name', 'description', 'uri', 'commit_hash', 'type'] as const

Let REQUEST_COUNT

REQUEST_COUNT: number = 0

Global counter for websocket request IDs

Const SAML_SOURCE_MUTABLE_FIELDS

SAML_SOURCE_MUTABLE_FIELDS: ["name", "authority_id", "issuer", "idp_sso_target_url_runtime_params", "name_identifier_format", "uid_attribute", "assertion_consumer_service_url", "idp_sso_target_url", "idp_cert", "idp_cert_fingerprint", "attribute_service_name", "attribute_statements", "request_attributes", "idp_slo_target_url", "slo_default_relay_state"] = ['name','authority_id','issuer','idp_sso_target_url_runtime_params','name_identifier_format','uid_attribute','assertion_consumer_service_url','idp_sso_target_url','idp_cert','idp_cert_fingerprint','attribute_service_name','attribute_statements','request_attributes','idp_slo_target_url','slo_default_relay_state'] as const

Const SETTINGS_MUTABLE_FIELDS

SETTINGS_MUTABLE_FIELDS: ["settings_string", "encryption_level"] = ['settings_string', 'encryption_level'] as const

Const SYSTEM_MUTABLE_FIELDS

SYSTEM_MUTABLE_FIELDS: ["name", "email", "description", "email", "capacity", "features", "bookable", "installed_ui_devices", "support_url", "modules", "zones"] = ['name','email','description','email','capacity','features','bookable','installed_ui_devices','support_url','modules','zones'] as const

Const TRIGGER_MUTABLE_FIELDS

TRIGGER_MUTABLE_FIELDS: ["name", "description", "enabled", "enable_webhook", "supported_methods", "actions", "conditions", "debounce_period", "important", "system_id"] = ['name','description','enabled','enable_webhook','supported_methods','actions','conditions','debounce_period','important','system_id'] as const

Const USER_MUTABLE_FIELDS

USER_MUTABLE_FIELDS: ["name", "email", "authority_id", "email", "phone", "country", "image", "metadata", "login_name", "staff_id", "first_name", "last_name", "support", "sys_admin"] = ['name','email','authority_id','email','phone','country','image','metadata','login_name','staff_id','first_name','last_name','support','sys_admin'] as const

Const ZONE_MUTABLE_FIELDS

ZONE_MUTABLE_FIELDS: ["name", "description", "triggers", "tags"] = ['name', 'description', 'triggers', 'tags'] as const

Functions

convertPairStringToMap

  • convertPairStringToMap(str: string): HashMap<string>

generateMockRepository

  • generateMockRepository(overrides?: any): any

generateMockSettings

  • generateMockSettings(overrides?: any): any

generateMockSystem

  • generateMockSystem(overrides?: any): any

generateNonce

  • generateNonce(length?: number): string
  • Create a nonce with the given length

    Parameters

    • Default value length: number = 40

      Length of the nonce string. Defaults to 40 characters

    Returns string

getFragments

removeFragment

  • removeFragment(name: string): void

toQueryString

  • toQueryString(map: HashMap): string

Object literals

Const MOCK_AUTHORITY

MOCK_AUTHORITY: object

config

config: {}

Type declaration

description

description: string = ""

dom

dom: string = "localhost:4200"

id

id: string = "mock-authority"

login_url

login_url: string = `/login?continue={{url}}`

logout_url

logout_url: string = `/logout`

name

name: string = "localhost:4200"

production

production: boolean = false

session

session: boolean = true

version

version: string = `2.0.0`

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc