Commands this handler can execute

interface Exec {
    addLog: ((log, alert?) => void);
    base64ToInteger: ((value, offset?, maxByteLength?) => number);
    base64ToString: ((args) => string);
    base64ToUInt8Array: ((value) => Uint8Array);
    cborDecode: ((input, encoding?) => any);
    cborEncode: ((...objs) => Uint8Array);
    closeIssue: ((issueHashId, comment?) => void);
    decrypt: ((args) => Uint8Array);
    dropCommand: ((commandHashId, removeFromScheduledCommands?, markAsDeleted?, reasonForMarkAsDeleted?) => void);
    encrypt: ((args) => {
        authTag: Uint8Array;
        encodedPayload: Uint8Array;
        initializationVector: Uint8Array;
    });
    expectNextReportBefore: ((before) => void);
    getDeviceFields: ((objectType, hashId) => null | FieldsFromServer);
    getFile: ((fileHashId) => Uint8Array);
    increaseReportingCounter: ((asOf?) => void);
    integerToBase64: ((value, maxByteLength?) => string);
    markCommandAsSent: ((commandHashId) => void);
    openIssue: ((args) => void);
    parseReport: ((args) => void);
    scheduleCommand: ((args) => Command);
    sendRequest: ((args) => null | WebResponse);
    setDeviceFields: ((fields, object?, logInAuditLog?) => void);
    stringToBase64: ((args) => string);
    stringToUint8Array: ((str, inputEncoding) => Uint8Array);
    uInt8ArrayToBase64: ((value) => string);
    uint8ArrayToString: ((uint8Array, outputEncoding) => string);
    addCommentToIssue(issueHashId, comment): void;
    getCredentials(hashId): string;
    updateGeometry(longitude, latitude): void;
}

Properties

addLog: ((log, alert?) => void)

Add a text to the log file of this activity

Type declaration

    • (log, alert?): void
    • Parameters

      • log: string

        Text to log.

      • Optional alert: boolean

        True to mark this activity as failed, triggering an email alert to subscribers. False by default

      Returns void

base64ToInteger: ((value, offset?, maxByteLength?) => number)

Decode a base64 string to an integer number

Type declaration

    • (value, offset?, maxByteLength?): number
    • Parameters

      • value: string

        The base64 encoded string

      • Optional offset: number

        Number of bytes to skip before starting to read. Defaults to 0.

      • Optional maxByteLength: number

        Number of bytes to read. Must satisfy 0 < byteLength <= 6. Defaults to 6.

      Returns number

Returns

A big endian signed integer

base64ToString: ((args) => string)

Decode a base64 string to a UTF-8 string

Type declaration

    • (args): string
    • Parameters

      • args: string

        The base64 encoded string

      Returns string

Returns

A UTF-8 string

Deprecated

use stringToUint8Array and uint8ArrayToString instead

base64ToUInt8Array: ((value) => Uint8Array)

Decode a a base64 string to a Uint8Array

Type declaration

    • (value): Uint8Array
    • Parameters

      • value: string

        The base64 encoded string

      Returns Uint8Array

Returns

Uint8Array

Deprecated

use stringToUint8Array instead

cborDecode: ((input, encoding?) => any)

Decode the first CBOR item in the input into a JavaScript object

Type declaration

    • (input, encoding?): any
    • Parameters

      • input: string | Uint8Array

        The input

      • Optional encoding: string

      Returns any

Returns

The decoded javascript object

cborEncode: ((...objs) => Uint8Array)

Encode one or more JavaScript objects into a buffer containing the CBOR bytes

Type declaration

    • (...objs): Uint8Array
    • Parameters

      • Rest ...objs: any[]

        any[]

      Returns Uint8Array

Returns

Uint8Array

closeIssue: ((issueHashId, comment?) => void)

Close an issue on the system

Type declaration

    • (issueHashId, comment?): void
    • Parameters

      • issueHashId: string

        hashId of the issue to close

      • Optional comment: string

        optional comment to add to the issue

      Returns void

decrypt: ((args) => Uint8Array)

Decrypt data

Type declaration

    • (args): Uint8Array
    • Parameters

      • args: DecryptArgs

        information about the data to decrypt and the encryption cipher

      Returns Uint8Array

Returns

decrypted data

dropCommand: ((commandHashId, removeFromScheduledCommands?, markAsDeleted?, reasonForMarkAsDeleted?) => void)

Drop a command from the list of scheduled commands

Type declaration

    • (commandHashId, removeFromScheduledCommands?, markAsDeleted?, reasonForMarkAsDeleted?): void
    • Parameters

      • commandHashId: string

        HashId of the command.

      • Optional removeFromScheduledCommands: boolean

        If true, the command will not appear in args.scheduledCommands anymore when the device type event handler is called in the future. True by default

      • Optional markAsDeleted: boolean

        If true, the deletedAt property of the command will be set to the current timestamp. False by default.

      • Optional reasonForMarkAsDeleted: string

      Returns void

encrypt: ((args) => {
    authTag: Uint8Array;
    encodedPayload: Uint8Array;
    initializationVector: Uint8Array;
})

Encrypt data

Type declaration

    • (args): {
          authTag: Uint8Array;
          encodedPayload: Uint8Array;
          initializationVector: Uint8Array;
      }
    • Parameters

      • args: EncryptArgs

        information about the data to encrypt and the encryption cipher

      Returns {
          authTag: Uint8Array;
          encodedPayload: Uint8Array;
          initializationVector: Uint8Array;
      }

      • authTag: Uint8Array
      • encodedPayload: Uint8Array
      • initializationVector: Uint8Array

Returns

object with the encrypted payload, IV and authtag

expectNextReportBefore: ((before) => void)

Inform the system when the next report is expected. The expected report counter is increased by one. It also creates an obligation for the event handler to call exec.increaseReportingCounter before before. If increaseReportingCounter is not called in time, the missed report counter will be increased by one. If too many reports have been missed consecutively, an issue will be created.

Type declaration

    • (before): void
    • Parameters

      • before: null | Date

        if null is provided, the existing obligation will be cleared (but the expected report counter will not be altered)

      Returns void

getDeviceFields: ((objectType, hashId) => null | FieldsFromServer)

Get the form fields of a location or port

Type declaration

getFile: ((fileHashId) => Uint8Array)

Get a file by its hashId

Type declaration

    • (fileHashId): Uint8Array
    • Parameters

      • fileHashId: string

        HashId of the file

      Returns Uint8Array

Returns

A (Node) buffer containing the contents of the file

increaseReportingCounter: ((asOf?) => void)

Inform the system that the device has obligated its duty to report in as specified earlier in exec.expectNextReportBefore. Call this function before informing the system of the next obligation through exec.expectNextReportBefore. This function increases the received report counter by 1 and resets the missed report counter to 0. Note that if this function is called multiple times for the same asOf, the system will show that the device has been reporting too often.

Type declaration

    • (asOf?): void
    • Parameters

      • Optional asOf: Date

        The timestamp at which the measurement cycle has been fulfilled, usually the current moment. If left out, the current moment is used.

      Returns void

integerToBase64: ((value, maxByteLength?) => string)

Encode an integer number into a base64 string

Type declaration

    • (value, maxByteLength?): string
    • Parameters

      • value: number

        The big endian signed integer

      • Optional maxByteLength: number

        Number of bytes to write. Must satisfy 0 < byteLength <= 6. Defaults to 6.

      Returns string

Returns

A base64 encoded value

markCommandAsSent: ((commandHashId) => void)

Inform the system that a command has been sent to the device. Will be used to block deletion of a(n overdue) command by a user. Users will never be notified at the startAt of a command if it is not marked as sent.

Type declaration

    • (commandHashId): void
    • Parameters

      • commandHashId: string

        HashId of the command.

      Returns void

openIssue: ((args) => void)

Open an issue on the system

Type declaration

parseReport: ((args) => void)

Parse a payload into a condition report

Type declaration

    • (args): void
    • Parameters

      Returns void

scheduleCommand: ((args) => Command)

Schedule a new command for this device

Type declaration

sendRequest: ((args) => null | WebResponse)

Perform an HTTP request

Type declaration

setDeviceFields: ((fields, object?, logInAuditLog?) => void)

Update the form fields of the device, its linked location or port

Type declaration

    • (fields, object?, logInAuditLog?): void
    • Parameters

      • fields: FieldsToServerUpdate

        data to store

      • Optional object: DeviceFieldsObject

        where to store it (device by default)

      • Optional logInAuditLog: boolean

        if true, the changes will be logged in the audit log

      Returns void

stringToBase64: ((args) => string)

Encode a UTF-8 string into a base64 string

Type declaration

    • (args): string
    • Parameters

      • args: string

        A UTF-8 string

      Returns string

Returns

The base64 encoded value

Deprecated

use stringToUint8Array and uint8ArrayToString instead

stringToUint8Array: ((str, inputEncoding) => Uint8Array)

Convert a string to a Uint8Array

Type declaration

    • (str, inputEncoding): Uint8Array
    • Parameters

      • str: string

        string to convert

      • inputEncoding: BufferEncoding

        encoding of the input string

      Returns Uint8Array

Returns

Uint8Array

uInt8ArrayToBase64: ((value) => string)

Encode a Uint8Array into a base64 string

Type declaration

    • (value): string
    • Parameters

      • value: Uint8Array

        Uint8Array

      Returns string

Returns

A base64 encoded value

Deprecated

use uint8ArrayToString instead

uint8ArrayToString: ((uint8Array, outputEncoding) => string)

Convert a Uint8Array to a string

Type declaration

    • (uint8Array, outputEncoding): string
    • Parameters

      • uint8Array: Uint8Array

        uint8Array to convert

      • outputEncoding: BufferEncoding

        encoding of the output string

      Returns string

Returns

string

Methods

  • Add a comment to an issue

    Parameters

    • issueHashId: string

      hashId of the issue to add the comment to

    • comment: string

      comment to add

    Returns void

  • Get the credentials used for an authenticated request

    Parameters

    • hashId: string

      hashId of the credentials

    Returns string

  • Update the geometry of the location

    Parameters

    • longitude: number

      new longitude of the location

    • latitude: number

      new latitude of the location

    Returns void