diff --git a/index.d.ts b/index.d.ts index 6873a6f..4b19803 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,6 @@ -import { Request, Response, NextFunction, Handler, Router } from 'express' -import { Engine, BpmnEngineOptions, BpmnEngineExecutionState, BpmnMessage } from 'bpmn-engine' +import { Request, Response, NextFunction, Router, Locals } from 'express'; +import { ParamsDictionary } from 'express-serve-static-core'; +import { Engine, BpmnEngineOptions, BpmnEngineExecutionState, BpmnMessage } from 'bpmn-engine'; import { LRUCache } from 'lru-cache'; import { Broker } from 'smqp'; @@ -83,6 +84,8 @@ export interface PostponedActivity extends BpmnMessage { executing?: BpmnMessage[]; } +type ExecutionListener = BpmnEngineOptions['listener']; + export class Engines { constructor(options: BpmnEngineMiddlewareOptions); adapter: IStorageAdapter; @@ -144,13 +147,19 @@ export interface SignalRequestBody { [x: string]: any; } -type tokenParam = { - token: string, -}; +interface TokenParam extends ParamsDictionary { + token: string; +} + +interface TokenActivityIdParam extends TokenParam { + activityId: string; +} -type activityIdParam = { - activityId: string, -}; +export interface EngineResponseLocals extends Locals { + engines: Engines; + adapter: IStorageAdapter; + listener: ExecutionListener; +} export class BpmnEngineMiddleware { readonly adapter?: IStorageAdapter; @@ -159,37 +168,37 @@ export class BpmnEngineMiddleware { constructor(options?: { adapter?: IStorageAdapter, engines?: Engines, engineOptions?: BpmnEngineOptions }); init(req: Request, res: Response, next: NextFunction): void; /** Add adapter, engines, and app engine listener to res.locals */ - addEngineLocals(req: Request, res: Response, next: NextFunction): void; + addEngineLocals(req: Request, res: Response, next: NextFunction): void; /** GET (*)?/version */ - getVersion(req: Request, res: Response<{version: string}>, next: NextFunction): void; + getVersion(req: Request, res: Response<{version: string}>, next: NextFunction): Promise; /** GET (*)?/deployment */ getDeployment(req: Request, res: Response<{name: string}>, next: NextFunction): Promise; /** POST (*)?/deployment/create */ create(req: Request, res: Response, next: NextFunction): Promise; /** POST (*)?/process-definition/:deploymentName/start */ - start(req: Request<{deploymentName: string}, StartRequestBody, ExecutionInstance>, res: Response, next: NextFunction): Promise; + start(req: Request<{deploymentName: string}, StartRequestBody, ExecutionInstance>, res: Response, next: NextFunction): Promise; /** GET (*)?/running */ getRunning(req: Request, res: Response, next: NextFunction): Promise; /** GET (*)?/status/:token */ - getStatusByToken(req: Request, res: Response, next: NextFunction): Promise; + getStatusByToken(req: Request, res: Response, next: NextFunction): Promise; /** GET (*)?/status/:token/:activityId */ - getActivityStatus(req: Request, res: Response, next: NextFunction): Promise; + getActivityStatus(req: Request, res: Response, next: NextFunction): Promise; /** POST (*)?/resume/:token */ - resumeByToken(req: Request, res: Response, next: NextFunction): Promise; + resumeByToken(req: Request, res: Response, next: NextFunction): Promise; /** POST (*)?/signal/:token */ - signalActivity(req: Request, res: Response, next: NextFunction): Promise; + signalActivity(req: Request, res: Response, next: NextFunction): Promise; /** POST (*)?/cancel/:token */ - cancelActivity(req: Request, res: Response, next: NextFunction): Promise; + cancelActivity(req: Request, res: Response, next: NextFunction): Promise; /** POST (*)?/fail/:token */ - failActivity(req: Request, res: Response, next: NextFunction): Promise; + failActivity(req: Request, res: Response, next: NextFunction): Promise; /** GET (*)?/state/:token */ - getStateByToken(req: Request, res: Response, next: NextFunction): Promise; + getStateByToken(req: Request, res: Response, next: NextFunction): Promise; /** DELETE (*)?/state/:token */ - deleteStateByToken(req: Request, res: Response, next: NextFunction): Promise; + deleteStateByToken(req: Request, res: Response, next: NextFunction): Promise; /** DELETE (*)?/internal/stop */ internalStopAll(req: Request, res: Response, next: NextFunction): void; /** DELETE (*)?/internal/stop/:token */ - internalStopByToken(req: Request, res: Response, next: NextFunction): void; + internalStopByToken(req: Request, res: Response, next: NextFunction): void; } interface MiddlewareReturnType extends Router { diff --git a/package.json b/package.json index 9e151e1..c243dcd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bpmn-middleware", - "version": "0.0.7", + "version": "0.0.8", "description": "BPMN engine express middleware", "type": "module", "main": "dist/main.cjs", diff --git a/src/index.js b/src/index.js index 936ae2e..5eb0543 100644 --- a/src/index.js +++ b/src/index.js @@ -184,7 +184,7 @@ BpmnEngineMiddleware.prototype.getStatusByToken = async function getStatusByToke BpmnEngineMiddleware.prototype.getActivityStatus = async function getActivityStatus(req, res, next) { try { const { token, activityId } = req.params; - const postponed = await this.engines.getPostponed(token, new BpmnPrefixListener(req.app)); + const postponed = await this.engines.getPostponed(token, res.locals.listener); const activity = postponed.find((p) => p.id === activityId); if (!activity) throw new HttpError(`Token ${token} has no running activity with id ${activityId}`, 400);