/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/stack-workflow@0.0.5/lib/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.CSDCStackWorkflow=void 0;const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),fs=require("fs"),path=require("path"),defaults=require("@aws-solutions-constructs/core"),aws_cdk_lib_1=require("aws-cdk-lib"),aws_iam_1=require("aws-cdk-lib/aws-iam"),aws_lambda_1=require("aws-cdk-lib/aws-lambda"),aws_lambda_nodejs_1=require("aws-cdk-lib/aws-lambda-nodejs"),aws_stepfunctions_1=require("aws-cdk-lib/aws-stepfunctions"),aws_stepfunctions_tasks_1=require("aws-cdk-lib/aws-stepfunctions-tasks"),constructs_1=require("constructs"),stack_action_state_machine_1=require("./stack-action-state-machine");class CSDCStackWorkflow extends constructs_1.Construct{constructor(t,a,e){super(t,a),this._generatePhysicalName=(t,a)=>{const e=t??"PhysicalName",s=(a??64)-e.length,n=[aws_cdk_lib_1.Stack.of(this).stackName,this.node.id];return defaults.generatePhysicalName(e,n,s)},this._createWorkflowFunction=()=>{const t=path.join(__dirname,"./lambda/workflow/index"),a=`${t}${fs.existsSync(t+".ts")?".ts":".js"}`,e=new aws_lambda_nodejs_1.NodejsFunction(this,"WorkflowFunction",{description:"Lambda function for workflow state machine",entry:a,handler:"handler",runtime:aws_lambda_1.Runtime.NODEJS_18_X,tracing:aws_cdk_lib_1.aws_lambda.Tracing.ACTIVE,architecture:aws_lambda_1.Architecture.X86_64,timeout:aws_cdk_lib_1.Duration.seconds(15),environment:{CALLBACK_BUCKET_NAME:this.callbackBucket.bucketName}}),s=defaults.buildLambdaFunction(this,{existingLambdaObj:e});return this._attachPolicy(s),this.callbackBucket.grantReadWrite(s),s},this._attachPolicy=t=>{if(!t.role)throw Error("Workflow function role is undefined.");new aws_iam_1.Policy(this,"WorkflowFunctionDefaultPolicy",{statements:[new aws_iam_1.PolicyStatement({effect:aws_iam_1.Effect.ALLOW,resources:[`arn:${aws_cdk_lib_1.Aws.PARTITION}:cloudformation:*:${aws_cdk_lib_1.Aws.ACCOUNT_ID}:stack/*`],actions:["cloudformation:DescribeStacks"]})]}).attachToRole(t.role)},this._chain=t=>{const a=new aws_stepfunctions_tasks_1.LambdaInvoke(this,"InputTask",{lambdaFunction:this.workflowFunction,payload:aws_stepfunctions_1.TaskInput.fromObject({Type:"Initial",Data:{ExecutionName:aws_stepfunctions_1.JsonPath.executionName,Input:aws_stepfunctions_1.TaskInput.fromJsonPathAt("$")}}),outputPath:"$.Payload"}),e=new aws_stepfunctions_tasks_1.StepFunctionsStartExecution(this,"StackExecution",{stateMachine:this.actionStateMachine,integrationPattern:aws_stepfunctions_1.IntegrationPattern.RUN_JOB,input:aws_stepfunctions_1.TaskInput.fromObject({Action:aws_stepfunctions_1.JsonPath.stringAt("$.Input.Action"),Token:aws_stepfunctions_1.JsonPath.taskToken,Input:aws_stepfunctions_1.JsonPath.stringAt("$.Input"),ExecutionName:aws_stepfunctions_1.JsonPath.stringAt("$.ExecutionName")})}),s=new aws_stepfunctions_tasks_1.StepFunctionsStartExecution(this,"SerialCallSelf",{stateMachine:{stateMachineArn:t},integrationPattern:aws_stepfunctions_1.IntegrationPattern.RUN_JOB,input:aws_stepfunctions_1.TaskInput.fromObject({Token:aws_stepfunctions_1.JsonPath.taskToken,Type:"CallSelf",Data:aws_stepfunctions_1.JsonPath.stringAt("$")})}),n=new aws_stepfunctions_tasks_1.StepFunctionsStartExecution(this,"ParallelCallSelf",{stateMachine:{stateMachineArn:t},integrationPattern:aws_stepfunctions_1.IntegrationPattern.RUN_JOB,input:aws_stepfunctions_1.TaskInput.fromObject({Token:aws_stepfunctions_1.JsonPath.taskToken,Type:"CallSelf",Data:aws_stepfunctions_1.JsonPath.stringAt("$")})}),i=new aws_stepfunctions_1.Map(this,"SerialMap",{maxConcurrency:1,itemsPath:aws_stepfunctions_1.JsonPath.stringAt("$")});i.iterator(s);const o=new aws_stepfunctions_1.Map(this,"ParallelMap",{maxConcurrency:40,itemsPath:aws_stepfunctions_1.JsonPath.stringAt("$")});o.iterator(n);const c=new aws_stepfunctions_1.Pass(this,"Pass"),r=new aws_stepfunctions_1.Choice(this,"TypeChoice",{outputPath:"$.Data"}).when(aws_stepfunctions_1.Condition.stringEquals("$.Type","Stack"),e).when(aws_stepfunctions_1.Condition.stringEquals("$.Type","Serial"),i).when(aws_stepfunctions_1.Condition.stringEquals("$.Type","Parallel"),o).otherwise(c);return a.next(r),a},this._output=()=>{new aws_cdk_lib_1.CfnOutput(this,"WorkflowStateMachineArn",{description:"Workflow State Machine Arn",value:this.workflowStateMachine.stateMachineArn}).overrideLogicalId("WorkflowStateMachineArn"),new aws_cdk_lib_1.CfnOutput(this,"ActionStateMachineArn",{description:"Action State Machine Arn",value:this.actionStateMachine.stateMachineArn}).overrideLogicalId("ActionStateMachineArn"),new aws_cdk_lib_1.CfnOutput(this,"CallbackBucketName",{description:"Callback Bucket Name",value:this.callbackBucket.bucketName}).overrideLogicalId("CallbackBucketName")},this.callbackBucket=defaults.buildS3Bucket(this,{bucketProps:{bucketName:this._generatePhysicalName("stack-workflow-callback",32)}}).bucket,this.actionStateMachine=new stack_action_state_machine_1.StackActionStateMachine(this,"ActionStateMachine",{callbackBucket:this.callbackBucket,policyStatementForRunStack:e?.policyStatementForRunStack}).actionStateMachine,this.workflowFunction=this._createWorkflowFunction();const s=this._generatePhysicalName("Workflow",80),n=`arn:${aws_cdk_lib_1.Aws.PARTITION}:states:${aws_cdk_lib_1.Aws.REGION}:${aws_cdk_lib_1.Aws.ACCOUNT_ID}:stateMachine:${s}`,i=this._chain(n),o=defaults.buildStateMachine(this,{stateMachineName:s,definitionBody:aws_stepfunctions_1.DefinitionBody.fromChainable(i),tracingEnabled:!0,timeout:aws_cdk_lib_1.Duration.hours(2)},{});this.workflowStateMachine=o.stateMachine,this._output()}}CSDCStackWorkflow[_a=JSII_RTTI_SYMBOL_1]={fqn:"stack-workflow.CSDCStackWorkflow",version:"0.0.5"},exports.CSDCStackWorkflow=CSDCStackWorkflow;
//# sourceMappingURL=/sm/f155fce10aa49a306cf2c9c5aef73d35ca0464ab8a93fb4c393934f4de9295f3.map