UNPKG

@mbc-cqrs-serverless/core

Version:
59 lines 2.79 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var StepFunctionService_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.StepFunctionService = void 0; const client_sfn_1 = require("@aws-sdk/client-sfn"); const common_1 = require("@nestjs/common"); const config_1 = require("@nestjs/config"); const CLIENT_INSTANCE = Symbol('step-func'); let StepFunctionService = StepFunctionService_1 = class StepFunctionService { constructor(config) { this.config = config; this.logger = new common_1.Logger(StepFunctionService_1.name); this[CLIENT_INSTANCE] = new client_sfn_1.SFNClient({ endpoint: config.get('SFN_ENDPOINT'), region: config.get('SFN_REGION'), }); } get client() { return this[CLIENT_INSTANCE]; } startExecution(arn, input, name) { return this.client.send(new client_sfn_1.StartExecutionCommand({ stateMachineArn: arn, name: name && name.length <= 80 ? name : undefined, input: JSON.stringify(input), })); } async resumeExecution(taskToken, output = {}) { try { this.logger.debug(`Resuming execution with token: ${taskToken.substring(0, 10)}...`); const wrappedOutput = { Payload: [[output]], }; return await this.client.send(new client_sfn_1.SendTaskSuccessCommand({ taskToken: taskToken, output: JSON.stringify(wrappedOutput), })); } catch (error) { this.logger.error(`Failed to resume execution: ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error.stack : undefined); throw error; } } }; exports.StepFunctionService = StepFunctionService; exports.StepFunctionService = StepFunctionService = StepFunctionService_1 = __decorate([ (0, common_1.Injectable)(), __metadata("design:paramtypes", [config_1.ConfigService]) ], StepFunctionService); //# sourceMappingURL=step-function.service.js.map