WorkflowContext #
import _ from "lodash";
import { KuzzleRequest, DocumentNotification, JSONObject } from "kuzzle";
import { Workflow } from "../workflow";
export class WorkflowContext {
/**
* Tenant index where the workflow document is present
*/
engineIndex: string;
/**
* Workflow currently executed
*/
workflow: Workflow;
/**
* Original payload who triggered the workflow.
*
* For trigger of type `notification` it's a DocumentNotification
* For trigger of type `event`, it can be a KuzzleRequest or any other kind of payload
*/
originalPayload: KuzzleRequest | DocumentNotification | JSONObject;
/**
* Extracted payload
*/
payload: JSONObject;
/**
* Additional information passed between actions
*/
props: JSONObject;
constructor({
engineIndex,
workflow,
originalPayload,
props,
}: {
engineIndex: string;
workflow: Workflow;
originalPayload: JSONObject;
props?: JSONObject;
}) {
this.engineIndex = engineIndex;
this.workflow = workflow;
this.originalPayload = originalPayload;
this.props = props || {};
this.payload = this.extractPayload();
}
extractPayload() {
const item = this.originalPayload;
return this.workflow.content.payloadPath === "."
? item
: _.get(item, this.workflow.content.payloadPath);
}
}
Edit this page on Github(opens new window)