Skip to main content

Script API reference

In scripts, the definitions below are available through the kreya object. Additionally all general Kreya APIs and bundled modules are available, see general script API reference.

kreya.trace('Starting script invocation of ' + kreya.script.current.name);

await kreya.invokeOperation('my-gRPC-operation');

let success = false;
while (!success) {
const result = await kreya.invokeOperation('my-rest-operation');
success = result.success;

await kreya.wait(100);
}

Variables​

script​

const script: InvokerScriptContainerScriptApi;

InvokerScriptContainerScriptApi
Kreya scripting API for scripts.

Functions​

invokeOperation()​

function invokeOperation(operationPath: string): Promise<ScriptOperationResult>;

Invoke an operation. Throws an error on an unsuccessful result if script.current.ensureSuccess is enabled.

Parameters​

ParameterTypeDescription
operationPathstringThe path of the operation to invoke. Must be relative to the script.

Returns​

Promise<ScriptOperationResult>

Returns the result of the operation invocation.

Type Aliases​

InvokerScriptContainerScriptApi​

type InvokerScriptContainerScriptApi = {
current: InvokerScriptCurrentScriptApi;
};

Kreya scripting API for scripts.

Properties​

current​
readonly current: InvokerScriptCurrentScriptApi;

The current script.


InvokerScriptCurrentScriptApi​

type InvokerScriptCurrentScriptApi = {
ensureSuccess: boolean;
name: string;
};

APIs to access a script.

Properties​

ensureSuccess​
ensureSuccess: boolean;

Whether invokeOperation throws an error when an operation is unsuccessful, using the result's success criteria. Defaults to false for each script run. Each invocation uses the value in effect when it starts.

name​
readonly name: string;

The name of the script.


ScriptOperationResult​

type ScriptOperationResult = {
status?: ScriptOperationStatus;
success: boolean;
ensureSuccess: void;
};

The result of an operation invocation.

Properties​

status?​
optional status?: ScriptOperationStatus;

Detailed information about the response status.

success​
success: boolean;

If the operation contains tests, this returns true if all tests were successful. If the operation does not contain tests, this returns true if the response status code indicates success.

Methods​

ensureSuccess()​
ensureSuccess(): void;

Throws an error if the operation invocation was not successful, using the same criteria as success.

Returns​

void


ScriptOperationStatus​

type ScriptOperationStatus = {
code: number;
detailMessage?: string;
statusName: string;
success: boolean;
};

The status of an operation response.

Properties​

code​
code: number;

The response status code, ex. 200 for a successful REST response.

detailMessage?​
optional detailMessage?: string;

An optional detail message about the status, received from the server.

statusName​
statusName: string;

The response status name, ex. OK for a successful REST response.

success​
success: boolean;

True if the status indicates success.