import * as express from 'express'; import { UserTaskInstance } from './DataModels'; import { Identity } from './DataModels/Iam/index'; import { ExternalEventBus } from './EngineEventBus'; import { EngineEventType, MiddlewareCallback } from './EngineEvents/index'; import { IApplicationInfoExtensionAdapter, IClusterExtensionAdapter, ICorrelationExtensionAdapter, ICronjobExtensionAdapter, IDataObjectInstanceExtensionAdapter, IEventExtensionAdapter, IExternalTaskExtensionAdapter, IFlowNodeInstanceExtensionAdapter, IIamExtensionAdapter, IManualTaskExtensionAdapter, IMessageEventExtensionAdapter, INotificationExtensionAdapter, IProcessDefinitionExtensionAdapter, IProcessInstanceExtensionAdapter, IProcessModelExtensionAdapter, ISignalEventExtensionAdapter, IUntypedTaskExtensionAdapter, IUserTaskExtensionAdapter } from './ExtensionAdapter'; import { EventViewModel, FlowNodeViewModel } from './ProcessModel/index'; /** * Describes the onLoad function, which can be exported by an extension. * It will be called by the Engine on startup. * * Example implementation: * export const onLoad: onLoadFunction = (engine: Engine) => {} */ export type OnLoad = (engine: Engine) => void | Promise; export type GetStatusInfo = () => Object | Promise; export type EngineExtension = { onLoad: OnLoad; getStatusInfo?: GetStatusInfo; }; export type Extension = { exports: EngineExtension; name: string; version: string; path: string; }; export type CustomServiceTaskHandlerContext = { token: { current: object; history: object; }; correlationId: string; correlationMetadata: any; currentFlowNode: FlowNodeViewModel; dataObjects: { [dataObjectId: string]: any; }; identity: Identity; previousFlowNodeId: string; processInstanceMetadata: any; }; /** * A CustomServiceTaskHandler is a used to execute custom Service Task Types - i.e. Service Task that are not External Service Tasks, or Http Service Tasks. * * @param context Contains information like the current token, Correlation- & Process Instance metadata or the service task's View Model. * @returns A result set to use as End Token. Must be a JSON object. */ export type CustomServiceTaskHandler> = (context: CustomServiceTaskHandlerContext) => Promise | TPayload; export type CustomHttpRouteRequest = { accepted: Array; baseUrl: string; body: object; complete: boolean; cookies: object; fresh: boolean; headers: object; hostname: string; httpVersion: string; httpVersionMajor: number; httpVersionMinor: number; identity: Identity; ip: string; ips: Array; method: string; originalUrl: string; params: object; path: string; protocol: string; query: { [key: string]: any; }; rawHeaders: Array; route: any; secure: boolean; signedCookies: object; stale: boolean; subdomains: Array; xhr: boolean; nonce?: string; }; export declare enum HttpResponseActionType { Send = "send", Json = "json", Jsonp = "jsonp", Download = "download", SendFile = "sendFile", End = "end", SendStatus = "sendStatus", Redirect = "redirect" } export type HttpResponseAction = HttpSendAction | HttpJsonAction | HttpSendFileAction | HttpDownloadAction | HttpEndAction | HttpSendStatusAction | HttpRedirectAction; export type HttpSendAction = { type: HttpResponseActionType.Send; result?: string; }; export type HttpJsonAction = { type: HttpResponseActionType.Json | HttpResponseActionType.Jsonp; result?: object; }; export type HttpSendFileAction = { type: HttpResponseActionType.SendFile; path?: string; options?: any; }; export type HttpDownloadAction = { type: HttpResponseActionType.Download; path: string; filename?: string; options?: any; }; export type HttpSendStatusAction = { type: HttpResponseActionType.SendStatus; }; export type HttpEndAction = { type: HttpResponseActionType.End; chunk?: any; encoding?: BufferEncoding; }; export type HttpRedirectAction = { type: HttpResponseActionType.Redirect; url: string; statusCode?: number; }; export type UserTaskAssignmentResolver = (UserTaskInstance: UserTaskInstance) => Array; export declare const userTaskAssignmentResolverTag = "userTaskAssignmentResolverTag"; export type CustomHttpRouteResult = { action: HttpResponseAction; append?: { [name: string]: string | Array | null; }; attachment?: string | null; links?: { [name: string]: string; }; location?: string; cookies?: Array<{ name: string; value: string; options?: express.CookieOptions; }>; clearCookies?: Array<{ name: string; options?: express.CookieOptions; }>; set?: { [name: string]: string; }; status?: number; trailers?: { [key: string]: string; }; type?: string; vary?: string | Array; }; export type CustomHttpRouteHandler = (request: CustomHttpRouteRequest) => Promise | CustomHttpRouteResult; /** * Additional Settings for a Custom HTTP Route. */ export type CustomHttpRouteOptions = { /** * If set, accessing the HTTP route will require a valid Auth Token. * Defaults to 'true'. */ protected?: boolean; }; export type RuntimeExpressionParameters = { token?: { current?: any; history?: { [flowNodeId: string]: any; }; }; correlationId?: string; correlationMetadata?: any; processModel?: { definitionId: string; definitionHash: string; id: string; name?: string; version?: string; }; identity?: { token: string; userId: string; userToken: string; claims: { [key: string]: boolean; }; }; processInstanceMetadata?: any; currentDataObject?: any; currentFlowNode?: FlowNodeViewModel; previousFlowNodeId?: string; dataObjects?: { [dataObjectId: string]: any; }; additionalProperties?: { [key: string]: any; }; allowNonObjectResults: boolean; }; /** * Contains interfaces for interaction with the Engine. */ export type Engine = { /** * Retrieves a section of the config by the given config key. * * @typedef TValue The expected type of the config to retrieve. * @param key The key of the config to get. * @returns The retrieved config. */ getConfig(key: string): TValue; /** * Registers a callback to execute before the resuming has started. * * @param callback The callback to call before the resuming has started. */ onBeforeResuming(callback: () => void | Promise): void; /** * Registers a callback to execute after the Engine has finished starting up. * * @param callback The callback to call after the Engine has finished starting up. */ onReady(callback: () => void | Promise): void; /** * Registers a custom Event Bus, which will replace the Engine's own internal Event Bus. * * **NOTE:** Can only be used BEFORE the {@link Engine.onReady} Event was fired! * * @param eventBus A custom {@link ExternalEventBus}. */ registerCustomEventBus(eventBus: ExternalEventBus): void; /** * Registers the given callback as an Event Middleware. * This middleware gets called whenever a Log Event occurs at the Engine. * * @param callback The function to call when a Log Event occurs. */ registerEventMiddleware(callback: MiddlewareCallback): void; /** * Removes an Event Middleware by its id. * * @async * @param callbackToRemove The callback to remove. */ removeEventMiddleware(callbackToRemove: MiddlewareCallback): void; /** * Registers the given callback as an Event Middleware for BPMN Message Events. * * @param callback The callback to execute, when a MessageEvent was received. * @param eventType The EventType to listen for. * If not specified 'OnFlowNodeExited' will be used. * The callback will only be executed when events with the given EventType are received. */ registerMessageEventMiddleware(callback: MiddlewareCallback, eventType?: EngineEventType.OnFlowNodeEntered | EngineEventType.OnFlowNodeExited): void; /** * Registers the given callback as an Event Middleware for BPMN Message Events. * * @param messageName The name of the message to listen for. * If set, the callback will only be executed when messages with the given name are received. * @param callback The callback to execute, when a MessageEvent was received. * @param eventType The EventType to listen for. * If not specified 'OnFlowNodeExited' will be used. * The callback will only be executed when events with the given EventType are received. */ registerMessageEventMiddleware(messageName: string, callback: MiddlewareCallback, eventType?: EngineEventType.OnFlowNodeEntered | EngineEventType.OnFlowNodeExited): void; /** * Registers the given callback as an Event Middleware for BPMN Signal Events. * * @param callback The callback to execute, when a SignalEvent was received. * @param eventType The EventType to listen for. * If not specified 'OnFlowNodeExited' will be used. * The callback will only be executed when events with the given EventType are received. */ registerSignalEventMiddleware(callback: MiddlewareCallback, eventType?: EngineEventType.OnFlowNodeEntered | EngineEventType.OnFlowNodeExited): void; /** * Registers the given callback as an Event Middleware for BPMN Signal Events. * * @param signalName The name of the signal to listen for. * If set, the callback will only be executed when signals with the given name are received. * @param callback The callback to execute, when a SignalEvent was received. * @param eventType The EventType to listen for. * If not specified 'OnFlowNodeExited' will be used. * The callback will only be executed when events with the given EventType are received. */ registerSignalEventMiddleware(signalName: string, callback: MiddlewareCallback, eventType?: EngineEventType.OnFlowNodeEntered | EngineEventType.OnFlowNodeExited): void; /** * Triggers a message event. * * @async * @param messageName The name of the message to trigger. * @param payload Optional: The payload with which to trigger the message. * @param processInstanceId Optional: The ID of the ProcessInstance on which to trigger the message event. * @param identity Optional: The requesting users identity. * @param correlationId Optional: The ID of a correlation to which the message should belong. * @param messageChannel Optional: The message channel to which the message is being sent. * @param eventId Optional: The ID by which to identity the unique signal. Will be auto-generated, if not provided. * @param resolver Optional: A function to call, after the Event has been processed. * * @returns A guid to identify the corresponding acknowledgement event. */ triggerMessageEvent: (messageName: string, payload?: TPayload, processInstanceId?: string, identity?: Identity, correlationId?: string, messageChannel?: string, eventId?: string, resolver?: Function) => Promise; /** * Triggers a message start event. * * @async * @param messageName The name of the message to trigger. * @param payload Optional: The payload with which to trigger the message. * @param identity Optional: The requesting users identity. * @param correlationId Optional: The ID of a correlation to which the message should belong. * @param messageChannel Optional: The message channel to which the message is being sent. * @param eventId Optional: The ID by which to identity the unique signal. Will be auto-generated, if not provided. * @param resolver Optional: A function to call, after the Event has been processed. * * @returns A guid to identify the corresponding acknowledgement event. */ triggerMessageStartEvent: (messageName: string, payload?: TPayload, identity?: Identity, correlationId?: string, messageChannel?: string, eventId?: string, resolver?: Function) => Promise; /** * Triggers a signal event. * * @async * @param signalName The name of the signal to trigger. * @param payload Optional: The payload with which to trigger the signal. * @param processInstanceId Optional: The ID of the ProcessInstance on which to trigger the signal event. * @param identity Optional: The requesting users identity. * @param correlationId Optional: The ID of a correlation to which the signal should belong. * @param signalChannel Optional: The signal channel to which the signal is being sent. * @param eventId Optional: The ID by which to identity the unique signal. Will be auto-generated, if not provided. * @param resolver Optional: A function to call, after the Event has been processed. * * @returns A guid to identify the corresponding acknowledgement event. */ triggerSignalEvent: (signalName: string, payload?: TPayload, processInstanceId?: string, identity?: Identity, correlationId?: string, signalChannel?: string, eventId?: string, resolver?: Function) => Promise; /** * Triggers a signal start event. * * @async * @param signalName The name of the signal to trigger. * @param payload Optional: The payload with which to trigger the signal. * @param identity Optional: The requesting users identity. * @param correlationId Optional: The ID of a correlation to which the signal should belong. * @param signalChannel Optional: The signal channel to which the signal is being sent. * @param eventId Optional: The ID by which to identity the unique signal. Will be auto-generated, if not provided. * @param resolver Optional: A function to call, after the Event has been processed. * * @returns A guid to identify the corresponding acknowledgement event. */ triggerSignalStartEvent: (signalName: string, payload?: TPayload, identity?: Identity, correlationId?: string, signalChannel?: string, eventId?: string, resolver?: Function) => Promise; /** * Returns a distinct list of all message events currently deployed to the engine. * * @async * @param processModelIds Optional: Only return message events for the given processModelIds. */ getMessageEvents(processModelIds?: string | Array): Promise>; /** * Returns a distinct list of all signal events currently deployed to the engine. * * @async * @param processModelIds Optional: Only return signal events for the given processModelIds. */ getSignalEvents(processModelIds?: string | Array): Promise>; registerCustomServiceTask(serviceTaskType: string, serviceTaskHandler: CustomServiceTaskHandler): void; registerUserTaskAssignmentResolver(resolver: UserTaskAssignmentResolver): void; removeCustomServiceTask(serviceTaskType: string): void; /** * Registers a HTTP Route at the Engine Server. These routes will be hosted by the engine itself and can be used to extend the Engine's native API. * * @param path The HTTP path to use * @param method The HTTP Method for the route. Currently supports GET, POST, PUT and DELETE * @param routeHandler A callback for handling requests against the route * @param options Additional settings for the HTTP route. */ registerHttpRoute(path: string, method: 'get' | 'post' | 'put' | 'delete', routeHandler: CustomHttpRouteHandler, options?: CustomHttpRouteOptions): void; executeRuntimeExpression(expression: string, params: RuntimeExpressionParameters): Promise; applicationInfo: IApplicationInfoExtensionAdapter; cluster: IClusterExtensionAdapter; correlations: ICorrelationExtensionAdapter; cronjobs: ICronjobExtensionAdapter; dataObjectInstances: IDataObjectInstanceExtensionAdapter; untypedTasks: IUntypedTaskExtensionAdapter; events: IEventExtensionAdapter; externalTasks: IExternalTaskExtensionAdapter; flowNodeInstances: IFlowNodeInstanceExtensionAdapter; iam: IIamExtensionAdapter; manualTasks: IManualTaskExtensionAdapter; messageEvents: IMessageEventExtensionAdapter; notification: INotificationExtensionAdapter; processDefinitions: IProcessDefinitionExtensionAdapter; processInstances: IProcessInstanceExtensionAdapter; processModels: IProcessModelExtensionAdapter; signalEvents: ISignalEventExtensionAdapter; userTasks: IUserTaskExtensionAdapter; };