UNPKG

@villedemontreal/workit-stepfunction-client

Version:

Camunda BPM client for WorkIt that works with Camunda platform powered by TypeScript

61 lines 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StepFunctionRepository = void 0; /* * Copyright (c) 2025 Ville de Montreal. All rights reserved. * Licensed under the MIT license. * See LICENSE file in the project root for full license information. */ const workit_types_1 = require("@villedemontreal/workit-types"); const sfnClient_1 = require("../sfnClient"); const fs = require("fs/promises"); const client_sfn_1 = require("@aws-sdk/client-sfn"); const params_1 = require("../config/constants/params"); /* eslint @typescript-eslint/no-unsafe-assignment: 0 */ /* eslint @typescript-eslint/no-unsafe-call: 0 */ /* eslint @typescript-eslint/no-unsafe-member-access: 0 */ // eslint-disable-next-line @typescript-eslint/no-var-requires const stringify = require('fast-safe-stringify'); class StepFunctionRepository { constructor(config) { this._config = config; this._client = new sfnClient_1.StepFunctionClient(this._config); } async deployWorkflow(absPath, override) { const workflow = (await fs.readFile(absPath)).toString(); const input = Object.assign({ definition: workflow }, override); const command = new client_sfn_1.CreateStateMachineCommand(input); return this._client.send(command); } startExecution(model) { const command = new client_sfn_1.StartExecutionCommand(model); return this._client.send(command); } sendTaskSuccess(message) { const payload = JSON.stringify(message.body); if (payload.length > params_1.MAX_PAYLOAD_LENGTH) { throw new workit_types_1.IncidentException("payload (message.body) can't exceed 256KB"); } const params = { output: message.body ? payload : '{}', taskToken: message.properties.jobKey }; const command = new client_sfn_1.SendTaskSuccessCommand(params); return this._client.send(command); } sendTaskFailure(error, message) { const params = { cause: stringify(error).substring(0, params_1.MAX_ERROR_CAUSE_LENGTH), taskToken: message.properties.jobKey, error: (error.code || error.name || 'UnhandledException').substring(0, params_1.MAX_ERROR_CODE_LENGTH), }; const command = new client_sfn_1.SendTaskFailureCommand(params); return this._client.send(command); } sendTaskHeartbeat(message) { const params = { taskToken: message.properties.jobKey, }; const command = new client_sfn_1.SendTaskHeartbeatCommand(params); return this._client.send(command); } } exports.StepFunctionRepository = StepFunctionRepository; //# sourceMappingURL=stepFunctionRepository.js.map