aws-local-stepfunctions 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -71,20 +71,27 @@ var ExecutionTimeoutError = class extends Error {
71
71
  }
72
72
  };
73
73
 
74
+ // src/error/ErrorWithCause.ts
75
+ var _errorCause;
76
+ var ErrorWithCause = class extends Error {
77
+ constructor(message, options) {
78
+ super(message);
79
+ __privateAdd(this, _errorCause, void 0);
80
+ __privateSet(this, _errorCause, options?.cause);
81
+ }
82
+ get cause() {
83
+ return __privateGet(this, _errorCause);
84
+ }
85
+ };
86
+ _errorCause = new WeakMap();
87
+
74
88
  // src/error/ExecutionError.ts
75
- var _wrappedError;
76
- var ExecutionError = class extends Error {
89
+ var ExecutionError = class extends ErrorWithCause {
77
90
  constructor(caughtError) {
78
- super(`Execution has failed with the following error: ${caughtError.message}`);
79
- __privateAdd(this, _wrappedError, void 0);
91
+ super(`Execution has failed with the following error: ${caughtError.message}`, { cause: caughtError });
80
92
  this.name = "ExecutionError";
81
- __privateSet(this, _wrappedError, caughtError);
82
- }
83
- get getWrappedError() {
84
- return __privateGet(this, _wrappedError);
85
93
  }
86
94
  };
87
- _wrappedError = new WeakMap();
88
95
 
89
96
  // src/util/random.ts
90
97
  function cyrb128(str) {
@@ -123,46 +130,58 @@ function getRandomNumber(min, max, rng = Math.random) {
123
130
  }
124
131
 
125
132
  // src/util/index.ts
133
+ var isBrowserEnvironment = typeof window !== "undefined" && typeof window.document !== "undefined";
126
134
  function isPlainObj(value) {
127
135
  return !!value && Object.getPrototypeOf(value) === Object.prototype;
128
136
  }
129
- function sleep(ms, abortSignal, rootAbortSignal) {
137
+ function sleep(ms, abortSignal) {
130
138
  return new Promise((resolve) => {
131
- if (abortSignal?.aborted || rootAbortSignal?.aborted) {
139
+ if (abortSignal?.aborted) {
132
140
  return resolve();
133
141
  }
134
142
  const onAbort = () => {
135
- abortSignal?.removeEventListener("abort", onAbort);
136
- rootAbortSignal?.removeEventListener("abort", onAbort);
137
143
  clearTimeout(timeout);
138
144
  resolve();
139
145
  };
140
146
  const timeout = setTimeout(() => {
141
147
  abortSignal?.removeEventListener("abort", onAbort);
142
- rootAbortSignal?.removeEventListener("abort", onAbort);
143
148
  resolve();
144
149
  }, ms);
145
- abortSignal?.addEventListener("abort", onAbort);
146
- rootAbortSignal?.addEventListener("abort", onAbort);
150
+ abortSignal?.addEventListener("abort", onAbort, { once: true });
147
151
  });
148
152
  }
149
153
  function byteToHex(byte) {
150
154
  return byte.toString(16).padStart(2, "0");
151
155
  }
156
+ function isRFC3339Timestamp(date) {
157
+ const regex = /^\d{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(\.\d+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9]))$/;
158
+ return regex.test(date);
159
+ }
160
+ function stringifyJSONValue(value) {
161
+ return JSON.stringify(value);
162
+ }
163
+ function clamp(value, min, max) {
164
+ if (min && value < min)
165
+ return min;
166
+ if (max && value > max)
167
+ return max;
168
+ return value;
169
+ }
152
170
 
153
- // src/stateMachine/JsonPath.ts
171
+ // src/stateMachine/jsonPath/JsonPath.ts
154
172
  var import_jsonpath_plus = require("jsonpath-plus");
155
- function jsonPathQuery(pathExpression, json, context) {
156
- if (pathExpression.startsWith("$$")) {
157
- return (0, import_jsonpath_plus.JSONPath)({ path: pathExpression.slice(1), json: context ?? null, wrap: false });
173
+
174
+ // src/stateMachine/jsonPath/constraints/BaseJsonPathConstraint.ts
175
+ var BaseJSONPathConstraint = class {
176
+ constructor(pathExpression) {
177
+ this.pathExpression = pathExpression;
158
178
  }
159
- return (0, import_jsonpath_plus.JSONPath)({ path: pathExpression, json, wrap: false });
160
- }
179
+ };
161
180
 
162
181
  // src/error/RuntimeError.ts
163
- var RuntimeError = class extends Error {
164
- constructor(message) {
165
- super(message);
182
+ var RuntimeError = class extends ErrorWithCause {
183
+ constructor(message, cause) {
184
+ super(message, { cause });
166
185
  this.name = "RuntimeError";
167
186
  this.retryable = true;
168
187
  this.catchable = true;
@@ -175,14 +194,6 @@ var RuntimeError = class extends Error {
175
194
  }
176
195
  };
177
196
 
178
- // src/error/predefined/StatesResultPathMatchFailureError.ts
179
- var StatesResultPathMatchFailureError = class extends RuntimeError {
180
- constructor() {
181
- super("States.ResultPathMatchFailure");
182
- this.name = "States.ResultPathMatchFailure";
183
- }
184
- };
185
-
186
197
  // src/error/predefined/StatesRuntimeError.ts
187
198
  var StatesRuntimeError = class extends RuntimeError {
188
199
  constructor(message = "States.Runtime") {
@@ -193,6 +204,43 @@ var StatesRuntimeError = class extends RuntimeError {
193
204
  }
194
205
  };
195
206
 
207
+ // src/stateMachine/jsonPath/constraints/DefinedValueConstraint.ts
208
+ var DefinedValueConstraint = class extends BaseJSONPathConstraint {
209
+ test(value) {
210
+ if (typeof value === "undefined") {
211
+ throw new StatesRuntimeError(`Path expression '${this.pathExpression}' does not point to a value`);
212
+ }
213
+ }
214
+ };
215
+
216
+ // src/stateMachine/jsonPath/JsonPath.ts
217
+ function jsonPathQuery(pathExpression, json, context, options) {
218
+ const defaultConstraints = [];
219
+ if (!options?.ignoreDefinedValueConstraint) {
220
+ defaultConstraints.push(DefinedValueConstraint);
221
+ }
222
+ const constraints = [...defaultConstraints, ...options?.constraints ?? []];
223
+ let evaluation;
224
+ if (pathExpression.startsWith("$$")) {
225
+ evaluation = (0, import_jsonpath_plus.JSONPath)({ path: pathExpression.slice(1), json: context ?? null, wrap: false });
226
+ } else {
227
+ evaluation = (0, import_jsonpath_plus.JSONPath)({ path: pathExpression, json, wrap: false });
228
+ }
229
+ for (const Constraint of constraints) {
230
+ const constraintObject = new Constraint(pathExpression);
231
+ constraintObject.test(evaluation);
232
+ }
233
+ return evaluation;
234
+ }
235
+
236
+ // src/error/predefined/StatesResultPathMatchFailureError.ts
237
+ var StatesResultPathMatchFailureError = class extends RuntimeError {
238
+ constructor() {
239
+ super("States.ResultPathMatchFailure");
240
+ this.name = "States.ResultPathMatchFailure";
241
+ }
242
+ };
243
+
196
244
  // src/stateMachine/intrinsicFunctions/ArgumentHandling.ts
197
245
  function validateArgumentType(allowedTypes, argPosition, funcArg, funcName) {
198
246
  let matchesAllowedType = false;
@@ -933,212 +981,300 @@ var StatesNoChoiceMatchedError = class extends RuntimeError {
933
981
  }
934
982
  };
935
983
 
984
+ // src/stateMachine/jsonPath/constraints/StringConstraint.ts
985
+ var StringConstraint = class extends BaseJSONPathConstraint {
986
+ test(value) {
987
+ if (typeof value !== "string") {
988
+ throw new StatesRuntimeError(
989
+ `Path expression '${this.pathExpression}' evaluated to ${stringifyJSONValue(value)}, but expected a string`
990
+ );
991
+ }
992
+ }
993
+ };
994
+
995
+ // src/stateMachine/jsonPath/constraints/NumberConstraint.ts
996
+ var NumberConstraint = class extends BaseJSONPathConstraint {
997
+ test(value) {
998
+ if (typeof value !== "number") {
999
+ throw new StatesRuntimeError(
1000
+ `Path expression '${this.pathExpression}' evaluated to ${stringifyJSONValue(value)}, but expected a number`
1001
+ );
1002
+ }
1003
+ }
1004
+ };
1005
+
1006
+ // src/stateMachine/jsonPath/constraints/BooleanConstraint.ts
1007
+ var BooleanConstraint = class extends BaseJSONPathConstraint {
1008
+ test(value) {
1009
+ if (typeof value !== "boolean") {
1010
+ throw new StatesRuntimeError(
1011
+ `Path expression '${this.pathExpression}' evaluated to ${stringifyJSONValue(value)}, but expected a boolean`
1012
+ );
1013
+ }
1014
+ }
1015
+ };
1016
+
1017
+ // src/stateMachine/jsonPath/constraints/RFC3339TimestampConstraint.ts
1018
+ var RFC3339TimestampConstraint = class extends BaseJSONPathConstraint {
1019
+ test(value) {
1020
+ if (typeof value !== "string" || !isRFC3339Timestamp(value)) {
1021
+ throw new StatesRuntimeError(
1022
+ `Path expression '${this.pathExpression}' evaluated to ${stringifyJSONValue(
1023
+ value
1024
+ )}, but expected a timestamp conforming to the RFC3339 profile`
1025
+ );
1026
+ }
1027
+ }
1028
+ };
1029
+
936
1030
  // src/stateMachine/stateActions/ChoiceStateAction.ts
937
1031
  var import_wildcard_match = __toESM(require("wildcard-match"), 1);
938
1032
  var ChoiceStateAction = class extends BaseStateAction {
939
1033
  constructor(stateDefinition, stateName) {
940
1034
  super(stateDefinition, stateName);
941
1035
  }
942
- testChoiceRule(choiceRule, input) {
1036
+ testChoiceRule(choiceRule, input, context) {
943
1037
  if ("And" in choiceRule) {
944
- return choiceRule.And.every((rule) => this.testChoiceRule(rule, input));
1038
+ return choiceRule.And.every((rule) => this.testChoiceRule(rule, input, context));
945
1039
  }
946
1040
  if ("Or" in choiceRule) {
947
- return choiceRule.Or.some((rule) => this.testChoiceRule(rule, input));
1041
+ return choiceRule.Or.some((rule) => this.testChoiceRule(rule, input, context));
948
1042
  }
949
1043
  if ("Not" in choiceRule) {
950
- return !this.testChoiceRule(choiceRule.Not, input);
1044
+ return !this.testChoiceRule(choiceRule.Not, input, context);
951
1045
  }
952
1046
  if ("StringEquals" in choiceRule) {
953
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1047
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
954
1048
  return varValue === choiceRule.StringEquals;
955
1049
  }
956
1050
  if ("StringEqualsPath" in choiceRule) {
957
- const varValue = jsonPathQuery(choiceRule.Variable, input);
958
- const stringValue = jsonPathQuery(choiceRule.StringEqualsPath, input);
1051
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1052
+ const stringValue = jsonPathQuery(choiceRule.StringEqualsPath, input, context, {
1053
+ constraints: [StringConstraint]
1054
+ });
959
1055
  return varValue === stringValue;
960
1056
  }
961
1057
  if ("StringLessThan" in choiceRule) {
962
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1058
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
963
1059
  return varValue < choiceRule.StringLessThan;
964
1060
  }
965
1061
  if ("StringLessThanPath" in choiceRule) {
966
- const varValue = jsonPathQuery(choiceRule.Variable, input);
967
- const stringValue = jsonPathQuery(choiceRule.StringLessThanPath, input);
1062
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1063
+ const stringValue = jsonPathQuery(choiceRule.StringLessThanPath, input, context, {
1064
+ constraints: [StringConstraint]
1065
+ });
968
1066
  return varValue < stringValue;
969
1067
  }
970
1068
  if ("StringGreaterThan" in choiceRule) {
971
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1069
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
972
1070
  return varValue > choiceRule.StringGreaterThan;
973
1071
  }
974
1072
  if ("StringGreaterThanPath" in choiceRule) {
975
- const varValue = jsonPathQuery(choiceRule.Variable, input);
976
- const stringValue = jsonPathQuery(choiceRule.StringGreaterThanPath, input);
1073
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1074
+ const stringValue = jsonPathQuery(choiceRule.StringGreaterThanPath, input, context, {
1075
+ constraints: [StringConstraint]
1076
+ });
977
1077
  return varValue > stringValue;
978
1078
  }
979
1079
  if ("StringLessThanEquals" in choiceRule) {
980
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1080
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
981
1081
  return varValue <= choiceRule.StringLessThanEquals;
982
1082
  }
983
1083
  if ("StringLessThanEqualsPath" in choiceRule) {
984
- const varValue = jsonPathQuery(choiceRule.Variable, input);
985
- const stringValue = jsonPathQuery(choiceRule.StringLessThanEqualsPath, input);
1084
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1085
+ const stringValue = jsonPathQuery(choiceRule.StringLessThanEqualsPath, input, context, {
1086
+ constraints: [StringConstraint]
1087
+ });
986
1088
  return varValue <= stringValue;
987
1089
  }
988
1090
  if ("StringGreaterThanEquals" in choiceRule) {
989
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1091
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
990
1092
  return varValue >= choiceRule.StringGreaterThanEquals;
991
1093
  }
992
1094
  if ("StringGreaterThanEqualsPath" in choiceRule) {
993
- const varValue = jsonPathQuery(choiceRule.Variable, input);
994
- const stringValue = jsonPathQuery(choiceRule.StringGreaterThanEqualsPath, input);
1095
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1096
+ const stringValue = jsonPathQuery(choiceRule.StringGreaterThanEqualsPath, input, context, {
1097
+ constraints: [StringConstraint]
1098
+ });
995
1099
  return varValue >= stringValue;
996
1100
  }
997
1101
  if ("StringMatches" in choiceRule) {
998
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1102
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
999
1103
  const isMatch = (0, import_wildcard_match.default)(choiceRule.StringMatches, { separator: false });
1000
1104
  return isMatch(varValue);
1001
1105
  }
1002
1106
  if ("NumericEquals" in choiceRule) {
1003
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1107
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1004
1108
  return varValue === choiceRule.NumericEquals;
1005
1109
  }
1006
1110
  if ("NumericEqualsPath" in choiceRule) {
1007
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1008
- const numberValue = jsonPathQuery(choiceRule.NumericEqualsPath, input);
1111
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1112
+ const numberValue = jsonPathQuery(choiceRule.NumericEqualsPath, input, context, {
1113
+ constraints: [NumberConstraint]
1114
+ });
1009
1115
  return varValue === numberValue;
1010
1116
  }
1011
1117
  if ("NumericLessThan" in choiceRule) {
1012
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1118
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1013
1119
  return varValue < choiceRule.NumericLessThan;
1014
1120
  }
1015
1121
  if ("NumericLessThanPath" in choiceRule) {
1016
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1017
- const numberValue = jsonPathQuery(choiceRule.NumericLessThanPath, input);
1122
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1123
+ const numberValue = jsonPathQuery(choiceRule.NumericLessThanPath, input, context, {
1124
+ constraints: [NumberConstraint]
1125
+ });
1018
1126
  return varValue < numberValue;
1019
1127
  }
1020
1128
  if ("NumericGreaterThan" in choiceRule) {
1021
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1129
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1022
1130
  return varValue > choiceRule.NumericGreaterThan;
1023
1131
  }
1024
1132
  if ("NumericGreaterThanPath" in choiceRule) {
1025
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1026
- const numberValue = jsonPathQuery(choiceRule.NumericGreaterThanPath, input);
1133
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1134
+ const numberValue = jsonPathQuery(choiceRule.NumericGreaterThanPath, input, context, {
1135
+ constraints: [NumberConstraint]
1136
+ });
1027
1137
  return varValue > numberValue;
1028
1138
  }
1029
1139
  if ("NumericLessThanEquals" in choiceRule) {
1030
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1140
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1031
1141
  return varValue <= choiceRule.NumericLessThanEquals;
1032
1142
  }
1033
1143
  if ("NumericLessThanEqualsPath" in choiceRule) {
1034
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1035
- const numberValue = jsonPathQuery(choiceRule.NumericLessThanEqualsPath, input);
1144
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1145
+ const numberValue = jsonPathQuery(choiceRule.NumericLessThanEqualsPath, input, context, {
1146
+ constraints: [NumberConstraint]
1147
+ });
1036
1148
  return varValue <= numberValue;
1037
1149
  }
1038
1150
  if ("NumericGreaterThanEquals" in choiceRule) {
1039
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1151
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1040
1152
  return varValue >= choiceRule.NumericGreaterThanEquals;
1041
1153
  }
1042
1154
  if ("NumericGreaterThanEqualsPath" in choiceRule) {
1043
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1044
- const numberValue = jsonPathQuery(choiceRule.NumericGreaterThanEqualsPath, input);
1155
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1156
+ const numberValue = jsonPathQuery(choiceRule.NumericGreaterThanEqualsPath, input, context, {
1157
+ constraints: [NumberConstraint]
1158
+ });
1045
1159
  return varValue >= numberValue;
1046
1160
  }
1047
1161
  if ("BooleanEquals" in choiceRule) {
1048
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1162
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1049
1163
  return varValue === choiceRule.BooleanEquals;
1050
1164
  }
1051
1165
  if ("BooleanEqualsPath" in choiceRule) {
1052
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1053
- const booleanValue = jsonPathQuery(choiceRule.BooleanEqualsPath, input);
1166
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1167
+ const booleanValue = jsonPathQuery(choiceRule.BooleanEqualsPath, input, context, {
1168
+ constraints: [BooleanConstraint]
1169
+ });
1054
1170
  return varValue === booleanValue;
1055
1171
  }
1056
1172
  if ("TimestampEquals" in choiceRule) {
1057
- const varValue = new Date(jsonPathQuery(choiceRule.Variable, input));
1173
+ const varValue = new Date(jsonPathQuery(choiceRule.Variable, input, context));
1058
1174
  const timestampValue = new Date(choiceRule.TimestampEquals);
1059
1175
  return varValue.getTime() === timestampValue.getTime();
1060
1176
  }
1061
1177
  if ("TimestampEqualsPath" in choiceRule) {
1062
- const varValue = new Date(jsonPathQuery(choiceRule.Variable, input));
1063
- const timestampValue = new Date(jsonPathQuery(choiceRule.TimestampEqualsPath, input));
1178
+ const varValue = new Date(jsonPathQuery(choiceRule.Variable, input, context));
1179
+ const timestampValue = new Date(
1180
+ jsonPathQuery(choiceRule.TimestampEqualsPath, input, context, {
1181
+ constraints: [RFC3339TimestampConstraint]
1182
+ })
1183
+ );
1064
1184
  return varValue.getTime() === timestampValue.getTime();
1065
1185
  }
1066
1186
  if ("TimestampLessThan" in choiceRule) {
1067
- const varValue = new Date(jsonPathQuery(choiceRule.Variable, input));
1187
+ const varValue = new Date(jsonPathQuery(choiceRule.Variable, input, context));
1068
1188
  const timestampValue = new Date(choiceRule.TimestampLessThan);
1069
1189
  return varValue < timestampValue;
1070
1190
  }
1071
1191
  if ("TimestampLessThanPath" in choiceRule) {
1072
- const varValue = new Date(jsonPathQuery(choiceRule.Variable, input));
1073
- const timestampValue = new Date(jsonPathQuery(choiceRule.TimestampLessThanPath, input));
1192
+ const varValue = new Date(jsonPathQuery(choiceRule.Variable, input, context));
1193
+ const timestampValue = new Date(
1194
+ jsonPathQuery(choiceRule.TimestampLessThanPath, input, context, {
1195
+ constraints: [RFC3339TimestampConstraint]
1196
+ })
1197
+ );
1074
1198
  return varValue < timestampValue;
1075
1199
  }
1076
1200
  if ("TimestampGreaterThan" in choiceRule) {
1077
- const varValue = new Date(jsonPathQuery(choiceRule.Variable, input));
1201
+ const varValue = new Date(jsonPathQuery(choiceRule.Variable, input, context));
1078
1202
  const timestampValue = new Date(choiceRule.TimestampGreaterThan);
1079
1203
  return varValue > timestampValue;
1080
1204
  }
1081
1205
  if ("TimestampGreaterThanPath" in choiceRule) {
1082
- const varValue = new Date(jsonPathQuery(choiceRule.Variable, input));
1083
- const timestampValue = new Date(jsonPathQuery(choiceRule.TimestampGreaterThanPath, input));
1206
+ const varValue = new Date(jsonPathQuery(choiceRule.Variable, input, context));
1207
+ const timestampValue = new Date(
1208
+ jsonPathQuery(choiceRule.TimestampGreaterThanPath, input, context, {
1209
+ constraints: [RFC3339TimestampConstraint]
1210
+ })
1211
+ );
1084
1212
  return varValue > timestampValue;
1085
1213
  }
1086
1214
  if ("TimestampLessThanEquals" in choiceRule) {
1087
- const varValue = new Date(jsonPathQuery(choiceRule.Variable, input));
1215
+ const varValue = new Date(jsonPathQuery(choiceRule.Variable, input, context));
1088
1216
  const timestampValue = new Date(choiceRule.TimestampLessThanEquals);
1089
1217
  return varValue <= timestampValue;
1090
1218
  }
1091
1219
  if ("TimestampLessThanEqualsPath" in choiceRule) {
1092
- const varValue = new Date(jsonPathQuery(choiceRule.Variable, input));
1093
- const timestampValue = new Date(jsonPathQuery(choiceRule.TimestampLessThanEqualsPath, input));
1220
+ const varValue = new Date(jsonPathQuery(choiceRule.Variable, input, context));
1221
+ const timestampValue = new Date(
1222
+ jsonPathQuery(choiceRule.TimestampLessThanEqualsPath, input, context, {
1223
+ constraints: [RFC3339TimestampConstraint]
1224
+ })
1225
+ );
1094
1226
  return varValue <= timestampValue;
1095
1227
  }
1096
1228
  if ("TimestampGreaterThanEquals" in choiceRule) {
1097
- const varValue = new Date(jsonPathQuery(choiceRule.Variable, input));
1229
+ const varValue = new Date(jsonPathQuery(choiceRule.Variable, input, context));
1098
1230
  const timestampValue = new Date(choiceRule.TimestampGreaterThanEquals);
1099
1231
  return varValue >= timestampValue;
1100
1232
  }
1101
1233
  if ("TimestampGreaterThanEqualsPath" in choiceRule) {
1102
- const varValue = new Date(jsonPathQuery(choiceRule.Variable, input));
1103
- const timestampValue = new Date(jsonPathQuery(choiceRule.TimestampGreaterThanEqualsPath, input));
1234
+ const varValue = new Date(jsonPathQuery(choiceRule.Variable, input, context));
1235
+ const timestampValue = new Date(
1236
+ jsonPathQuery(choiceRule.TimestampGreaterThanEqualsPath, input, context, {
1237
+ constraints: [RFC3339TimestampConstraint]
1238
+ })
1239
+ );
1104
1240
  return varValue >= timestampValue;
1105
1241
  }
1106
1242
  if ("IsNull" in choiceRule) {
1107
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1243
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1108
1244
  const isNullTrue = choiceRule.IsNull;
1109
1245
  return isNullTrue && varValue === null;
1110
1246
  }
1111
1247
  if ("IsPresent" in choiceRule) {
1112
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1248
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context, { ignoreDefinedValueConstraint: true });
1113
1249
  const IsPresentTrue = choiceRule.IsPresent;
1114
1250
  return IsPresentTrue && varValue !== void 0;
1115
1251
  }
1116
1252
  if ("IsNumeric" in choiceRule) {
1117
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1253
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1118
1254
  const IsNumericTrue = choiceRule.IsNumeric;
1119
1255
  return IsNumericTrue && typeof varValue === "number";
1120
1256
  }
1121
1257
  if ("IsString" in choiceRule) {
1122
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1258
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1123
1259
  const IsStringTrue = choiceRule.IsString;
1124
1260
  return IsStringTrue && typeof varValue === "string";
1125
1261
  }
1126
1262
  if ("IsBoolean" in choiceRule) {
1127
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1263
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1128
1264
  const IsBooleanTrue = choiceRule.IsBoolean;
1129
1265
  return IsBooleanTrue && typeof varValue === "boolean";
1130
1266
  }
1131
1267
  if ("IsTimestamp" in choiceRule) {
1132
- const varValue = jsonPathQuery(choiceRule.Variable, input);
1268
+ const varValue = jsonPathQuery(choiceRule.Variable, input, context);
1133
1269
  const IsTimestampTrue = choiceRule.IsTimestamp;
1134
- return IsTimestampTrue && /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(Z|(\+|-)\d{2}:\d{2})/.test(varValue);
1270
+ return IsTimestampTrue && isRFC3339Timestamp(varValue);
1135
1271
  }
1136
1272
  return false;
1137
1273
  }
1138
1274
  async execute(input, context, options) {
1139
1275
  const state = this.stateDefinition;
1140
1276
  for (const choice of state.Choices) {
1141
- const choiceIsMatch = this.testChoiceRule(choice, input);
1277
+ const choiceIsMatch = this.testChoiceRule(choice, input, context);
1142
1278
  if (choiceIsMatch) {
1143
1279
  return { stateResult: input, nextState: choice.Next, isEndState: false };
1144
1280
  }
@@ -1164,7 +1300,56 @@ var FailStateAction = class extends BaseStateAction {
1164
1300
  super(stateDefinition, stateName);
1165
1301
  }
1166
1302
  async execute(input, context, options) {
1167
- throw new FailStateError(this.stateDefinition.Error, this.stateDefinition.Cause);
1303
+ const state = this.stateDefinition;
1304
+ let error = state.Error;
1305
+ let cause = state.Cause;
1306
+ if (state.ErrorPath) {
1307
+ error = jsonPathQuery(state.ErrorPath, input, context, {
1308
+ constraints: [StringConstraint]
1309
+ });
1310
+ }
1311
+ if (state.CausePath) {
1312
+ cause = jsonPathQuery(state.CausePath, input, context, {
1313
+ constraints: [StringConstraint]
1314
+ });
1315
+ }
1316
+ throw new FailStateError(error, cause);
1317
+ }
1318
+ };
1319
+
1320
+ // src/stateMachine/jsonPath/constraints/ArrayConstraint.ts
1321
+ var ArrayConstraint = class extends BaseJSONPathConstraint {
1322
+ test(value) {
1323
+ if (!Array.isArray(value)) {
1324
+ throw new StatesRuntimeError(
1325
+ `Path expression '${this.pathExpression}' evaluated to ${stringifyJSONValue(value)}, but expected an array`
1326
+ );
1327
+ }
1328
+ }
1329
+ };
1330
+
1331
+ // src/stateMachine/jsonPath/constraints/IntegerConstraint.ts
1332
+ var IntegerConstraint = class extends BaseJSONPathConstraint {
1333
+ test(value) {
1334
+ if (!Number.isInteger(value)) {
1335
+ throw new StatesRuntimeError(
1336
+ `Path expression '${this.pathExpression}' evaluated to ${stringifyJSONValue(value)}, but expected an integer`
1337
+ );
1338
+ }
1339
+ }
1340
+ static greaterThanOrEqual(n) {
1341
+ return class extends this {
1342
+ test(value) {
1343
+ super.test(value);
1344
+ if (value < n) {
1345
+ throw new StatesRuntimeError(
1346
+ `Path expression '${this.pathExpression}' evaluated to ${stringifyJSONValue(
1347
+ value
1348
+ )}, but expected an integer >= ${n}`
1349
+ );
1350
+ }
1351
+ }
1352
+ };
1168
1353
  }
1169
1354
  };
1170
1355
 
@@ -1192,28 +1377,39 @@ var MapStateAction = class extends BaseStateAction {
1192
1377
  Value: item
1193
1378
  }
1194
1379
  };
1195
- if (state.Parameters) {
1196
- paramValue = processPayloadTemplate(state.Parameters, input, context);
1380
+ if (state.Parameters || state.ItemSelector) {
1381
+ const parameters = state.ItemSelector ?? state.Parameters;
1382
+ paramValue = processPayloadTemplate(parameters, input, context);
1197
1383
  }
1198
- const execution = stateMachine.run(paramValue ?? item, options?.runOptions);
1384
+ const execution = stateMachine.run(paramValue ?? item, options.runOptions);
1199
1385
  this.executionAbortFuncs.push(execution.abort);
1200
- this.forwardEventsToRootEventLogger(options?.eventLogger, execution.eventLogs, index, options?.rawInput);
1386
+ this.forwardEventsToRootEventLogger(options.eventLogger, execution.eventLogs, index, options.rawInput);
1201
1387
  return execution.result;
1202
1388
  }
1203
1389
  async execute(input, context, options) {
1204
1390
  const state = this.stateDefinition;
1205
1391
  let items = input;
1206
1392
  if (state.ItemsPath) {
1207
- items = jsonPathQuery(state.ItemsPath, input, context);
1393
+ items = jsonPathQuery(state.ItemsPath, input, context, {
1394
+ constraints: [ArrayConstraint]
1395
+ });
1208
1396
  }
1209
1397
  if (!Array.isArray(items)) {
1210
1398
  throw new StatesRuntimeError("Input of Map state must be an array or ItemsPath property must point to an array");
1211
1399
  }
1212
- const iteratorStateMachine = new StateMachine(state.Iterator, {
1213
- ...options?.stateMachineOptions,
1214
- validationOptions: { _noValidate: true }
1400
+ const iteratorDefinition = state.ItemProcessor ?? state.Iterator;
1401
+ const iteratorStateMachine = new StateMachine(iteratorDefinition, {
1402
+ ...options.stateMachineOptions,
1403
+ validationOptions: { noValidate: true }
1215
1404
  });
1216
- const limit = (0, import_p_limit.default)(state.MaxConcurrency || DEFAULT_MAX_CONCURRENCY);
1405
+ let maxConcurrency = state.MaxConcurrency;
1406
+ if (state.MaxConcurrencyPath) {
1407
+ maxConcurrency = jsonPathQuery(state.MaxConcurrencyPath, input, context, {
1408
+ constraints: [IntegerConstraint.greaterThanOrEqual(0)],
1409
+ ignoreDefinedValueConstraint: true
1410
+ });
1411
+ }
1412
+ const limit = (0, import_p_limit.default)(maxConcurrency || DEFAULT_MAX_CONCURRENCY);
1217
1413
  const processedItemsPromise = items.map(
1218
1414
  (item, i) => limit(() => this.processItem(iteratorStateMachine, item, input, context, i, options))
1219
1415
  );
@@ -1223,7 +1419,7 @@ var MapStateAction = class extends BaseStateAction {
1223
1419
  } catch (error) {
1224
1420
  this.executionAbortFuncs.forEach((abort) => abort());
1225
1421
  if (error instanceof ExecutionError) {
1226
- throw error.getWrappedError;
1422
+ throw error.cause;
1227
1423
  }
1228
1424
  throw error;
1229
1425
  } finally {
@@ -1249,12 +1445,12 @@ var ParallelStateAction = class extends BaseStateAction {
1249
1445
  }
1250
1446
  processBranch(branch, input, context, options) {
1251
1447
  const stateMachine = new StateMachine(branch, {
1252
- ...options?.stateMachineOptions,
1253
- validationOptions: { _noValidate: true }
1448
+ ...options.stateMachineOptions,
1449
+ validationOptions: { noValidate: true }
1254
1450
  });
1255
- const execution = stateMachine.run(input, options?.runOptions);
1451
+ const execution = stateMachine.run(input, options.runOptions);
1256
1452
  this.executionAbortFuncs.push(execution.abort);
1257
- this.forwardEventsToRootEventLogger(options?.eventLogger, execution.eventLogs, options?.rawInput);
1453
+ this.forwardEventsToRootEventLogger(options.eventLogger, execution.eventLogs, options.rawInput);
1258
1454
  return execution.result;
1259
1455
  }
1260
1456
  async execute(input, context, options) {
@@ -1269,7 +1465,7 @@ var ParallelStateAction = class extends BaseStateAction {
1269
1465
  } catch (error) {
1270
1466
  this.executionAbortFuncs.forEach((abort) => abort());
1271
1467
  if (error instanceof ExecutionError) {
1272
- throw error.getWrappedError;
1468
+ throw error.cause;
1273
1469
  }
1274
1470
  throw error;
1275
1471
  }
@@ -1299,16 +1495,39 @@ var SucceedStateAction = class extends BaseStateAction {
1299
1495
  }
1300
1496
  };
1301
1497
 
1498
+ // src/error/predefined/StatesTimeoutError.ts
1499
+ var StatesTimeoutError = class extends RuntimeError {
1500
+ constructor() {
1501
+ super("States.Timeout");
1502
+ this.name = "States.Timeout";
1503
+ }
1504
+ };
1505
+
1302
1506
  // src/aws/LambdaClient.ts
1303
1507
  var import_client_lambda = require("@aws-sdk/client-lambda");
1304
1508
  var import_credential_providers = require("@aws-sdk/credential-providers");
1509
+
1510
+ // src/error/LambdaInvocationError.ts
1511
+ var LambdaInvocationError = class extends RuntimeError {
1512
+ constructor(name, message, cause) {
1513
+ super(message, cause);
1514
+ this.name = name;
1515
+ }
1516
+ };
1517
+
1518
+ // src/aws/LambdaClient.ts
1305
1519
  var LambdaClient = class {
1306
1520
  constructor(config) {
1307
1521
  this.client = new import_client_lambda.LambdaClient({});
1308
1522
  if (config) {
1309
1523
  if (!config.region) {
1310
1524
  throw new StatesRuntimeError(
1311
- "'awsConfig' option was specified for state machine, but 'region' property is not set"
1525
+ "'awsConfig' option was specified in state machine constructor, but 'region' property is not set."
1526
+ );
1527
+ }
1528
+ if (!config.credentials) {
1529
+ throw new StatesRuntimeError(
1530
+ "'awsConfig' option was specified in state machine constructor, but 'credentials' property is not set."
1312
1531
  );
1313
1532
  }
1314
1533
  if (config.credentials) {
@@ -1331,6 +1550,12 @@ var LambdaClient = class {
1331
1550
  } else if (config.credentials?.accessKeys) {
1332
1551
  this.client = new import_client_lambda.LambdaClient({ region: config.region, credentials: config.credentials.accessKeys });
1333
1552
  }
1553
+ } else {
1554
+ if (isBrowserEnvironment) {
1555
+ throw new StatesRuntimeError(
1556
+ "aws-local-stepfunctions is running in a browser environment and your state machine definition contains a state of type 'Task'. In order to invoke the Lambda function, you must provide an AWS region and credentials in the state machine constructor by passing the 'awsConfig' option."
1557
+ );
1558
+ }
1334
1559
  }
1335
1560
  }
1336
1561
  async invokeFunction(funcNameOrArn, payload) {
@@ -1347,7 +1572,11 @@ var LambdaClient = class {
1347
1572
  }
1348
1573
  if (invocationResult.FunctionError) {
1349
1574
  const errorResult = resultValue;
1350
- throw new FailStateError(errorResult.errorType, `Execution of Lambda function '${funcNameOrArn}' failed`);
1575
+ throw new LambdaInvocationError(
1576
+ errorResult.errorType,
1577
+ `${errorResult.errorType}: ${errorResult.errorMessage}`,
1578
+ errorResult
1579
+ );
1351
1580
  }
1352
1581
  return resultValue;
1353
1582
  }
@@ -1357,15 +1586,46 @@ var LambdaClient = class {
1357
1586
  var TaskStateAction = class extends BaseStateAction {
1358
1587
  constructor(stateDefinition, stateName) {
1359
1588
  super(stateDefinition, stateName);
1589
+ this.timeoutAbortController = new AbortController();
1590
+ }
1591
+ createTimeoutPromise(input, context) {
1592
+ const state = this.stateDefinition;
1593
+ if (!state.TimeoutSeconds && !state.TimeoutSecondsPath)
1594
+ return;
1595
+ let timeout;
1596
+ if (state.TimeoutSeconds) {
1597
+ timeout = state.TimeoutSeconds;
1598
+ } else if (state.TimeoutSecondsPath) {
1599
+ timeout = jsonPathQuery(state.TimeoutSecondsPath, input, context, {
1600
+ constraints: [IntegerConstraint.greaterThanOrEqual(1)]
1601
+ });
1602
+ }
1603
+ return new Promise((_, reject) => {
1604
+ const handleTimeoutAbort = () => clearTimeout(timeoutId);
1605
+ const timeoutId = setTimeout(() => {
1606
+ this.timeoutAbortController.signal.removeEventListener("abort", handleTimeoutAbort);
1607
+ reject(new StatesTimeoutError());
1608
+ }, timeout * 1e3);
1609
+ this.timeoutAbortController.signal.addEventListener("abort", handleTimeoutAbort, { once: true });
1610
+ });
1360
1611
  }
1361
1612
  async execute(input, context, options) {
1362
1613
  const state = this.stateDefinition;
1363
- if (options?.overrideFn) {
1364
- const result2 = await options.overrideFn(input);
1365
- return this.buildExecutionResult(result2);
1614
+ const racingPromises = [];
1615
+ const timeoutPromise = this.createTimeoutPromise(input, context);
1616
+ if (options.overrideFn) {
1617
+ const resultPromise = options.overrideFn(input);
1618
+ racingPromises.push(resultPromise);
1619
+ } else {
1620
+ const lambdaClient = new LambdaClient(options.awsConfig);
1621
+ const resultPromise = lambdaClient.invokeFunction(state.Resource, input);
1622
+ racingPromises.push(resultPromise);
1623
+ }
1624
+ if (timeoutPromise) {
1625
+ racingPromises.push(timeoutPromise);
1366
1626
  }
1367
- const lambdaClient = new LambdaClient(options?.awsConfig);
1368
- const result = await lambdaClient.invokeFunction(state.Resource, input);
1627
+ const result = await Promise.race(racingPromises);
1628
+ this.timeoutAbortController.abort();
1369
1629
  return this.buildExecutionResult(result);
1370
1630
  }
1371
1631
  };
@@ -1377,44 +1637,41 @@ var WaitStateAction = class extends BaseStateAction {
1377
1637
  }
1378
1638
  async execute(input, context, options) {
1379
1639
  const state = this.stateDefinition;
1380
- if (options?.waitTimeOverrideOption !== void 0) {
1381
- await sleep(options.waitTimeOverrideOption, options.abortSignal, options.rootAbortSignal);
1640
+ if (options.waitTimeOverrideOption !== void 0) {
1641
+ await sleep(options.waitTimeOverrideOption, options.abortSignal);
1382
1642
  return this.buildExecutionResult(input);
1383
1643
  }
1384
1644
  if (state.Seconds) {
1385
- await sleep(state.Seconds * 1e3, options?.abortSignal, options?.rootAbortSignal);
1645
+ await sleep(state.Seconds * 1e3, options.abortSignal);
1386
1646
  } else if (state.Timestamp) {
1387
1647
  const dateTimestamp = new Date(state.Timestamp);
1388
1648
  const currentTime = Date.now();
1389
1649
  const timeDiff = dateTimestamp.getTime() - currentTime;
1390
- await sleep(timeDiff, options?.abortSignal, options?.rootAbortSignal);
1650
+ await sleep(timeDiff, options.abortSignal);
1391
1651
  } else if (state.SecondsPath) {
1392
- const seconds = jsonPathQuery(state.SecondsPath, input, context);
1393
- await sleep(seconds * 1e3, options?.abortSignal, options?.rootAbortSignal);
1652
+ const seconds = jsonPathQuery(state.SecondsPath, input, context, {
1653
+ constraints: [IntegerConstraint.greaterThanOrEqual(0)]
1654
+ });
1655
+ await sleep(seconds * 1e3, options.abortSignal);
1394
1656
  } else if (state.TimestampPath) {
1395
- const timestamp = jsonPathQuery(state.TimestampPath, input, context);
1657
+ const timestamp = jsonPathQuery(state.TimestampPath, input, context, {
1658
+ constraints: [RFC3339TimestampConstraint]
1659
+ });
1396
1660
  const dateTimestamp = new Date(timestamp);
1397
1661
  const currentTime = Date.now();
1398
1662
  const timeDiff = dateTimestamp.getTime() - currentTime;
1399
- await sleep(timeDiff, options?.abortSignal, options?.rootAbortSignal);
1663
+ await sleep(timeDiff, options.abortSignal);
1400
1664
  }
1401
1665
  return this.buildExecutionResult(input);
1402
1666
  }
1403
1667
  };
1404
1668
 
1405
- // src/error/predefined/StatesTimeoutError.ts
1406
- var StatesTimeoutError = class extends RuntimeError {
1407
- constructor() {
1408
- super("States.Timeout");
1409
- this.name = "States.Timeout";
1410
- }
1411
- };
1412
-
1413
1669
  // src/stateMachine/StateExecutor.ts
1414
1670
  var import_cloneDeep2 = __toESM(require("lodash/cloneDeep.js"), 1);
1415
1671
  var DEFAULT_MAX_ATTEMPTS = 3;
1416
1672
  var DEFAULT_INTERVAL_SECONDS = 1;
1417
1673
  var DEFAULT_BACKOFF_RATE = 2;
1674
+ var DEFAULT_JITTER_STRATEGY = "NONE";
1418
1675
  var WILDCARD_ERROR = "States.ALL";
1419
1676
  var TASK_STATE_WILDCARD_ERROR = "States.TaskFailed";
1420
1677
  var StateExecutor = class {
@@ -1456,13 +1713,34 @@ var StateExecutor = class {
1456
1713
  const processedResult = this.processResult(currResult, rawInput, context);
1457
1714
  return { stateResult: processedResult, nextState, isEndState };
1458
1715
  } catch (error) {
1459
- const { shouldRetry, waitTimeBeforeRetry } = this.shouldRetry(error);
1460
- if (shouldRetry && waitTimeBeforeRetry) {
1461
- await sleep(waitTimeBeforeRetry, options.abortSignal, options.runOptions?._rootAbortSignal);
1716
+ options.eventLogger.dispatchStateFailedEvent(
1717
+ this.stateName,
1718
+ this.stateDefinition.Type,
1719
+ input,
1720
+ error
1721
+ );
1722
+ const { shouldRetry, waitTimeBeforeRetry, retrierIndex } = this.shouldRetry(error);
1723
+ if (shouldRetry) {
1724
+ const stateDefinition = this.stateDefinition;
1725
+ await sleep(waitTimeBeforeRetry, options.abortSignal);
1726
+ options.eventLogger.dispatchStateRetriedEvent(
1727
+ this.stateName,
1728
+ stateDefinition.Type,
1729
+ input,
1730
+ stateDefinition.Retry[retrierIndex],
1731
+ this.retrierAttempts[retrierIndex]
1732
+ );
1462
1733
  return this.execute(input, context, options);
1463
1734
  }
1464
- const { nextState, errorOutput, resultPath } = this.catchError(error);
1735
+ const { nextState, errorOutput, resultPath, catcherIndex } = this.catchError(error);
1465
1736
  if (nextState && errorOutput) {
1737
+ const stateDefinition = this.stateDefinition;
1738
+ options.eventLogger.dispatchStateCaughtEvent(
1739
+ this.stateName,
1740
+ stateDefinition.Type,
1741
+ input,
1742
+ stateDefinition.Catch[catcherIndex]
1743
+ );
1466
1744
  return { stateResult: processResultPath(resultPath, rawInput, errorOutput), nextState, isEndState: false };
1467
1745
  }
1468
1746
  throw error;
@@ -1506,11 +1784,16 @@ var StateExecutor = class {
1506
1784
  }
1507
1785
  for (let i = 0; i < this.stateDefinition.Retry.length; i++) {
1508
1786
  const retrier = this.stateDefinition.Retry[i];
1787
+ const jitterStrategy = retrier.JitterStrategy ?? DEFAULT_JITTER_STRATEGY;
1509
1788
  const maxAttempts = retrier.MaxAttempts ?? DEFAULT_MAX_ATTEMPTS;
1510
1789
  const intervalSeconds = retrier.IntervalSeconds ?? DEFAULT_INTERVAL_SECONDS;
1511
1790
  const backoffRate = retrier.BackoffRate ?? DEFAULT_BACKOFF_RATE;
1512
- const waitTimeBeforeRetry = intervalSeconds * Math.pow(backoffRate, this.retrierAttempts[i]) * 1e3;
1791
+ const waitInterval = intervalSeconds * Math.pow(backoffRate, this.retrierAttempts[i]);
1513
1792
  const retryable = error.isRetryable ?? true;
1793
+ let waitTimeBeforeRetry = clamp(waitInterval, 1, retrier.MaxDelaySeconds) * 1e3;
1794
+ if (jitterStrategy === "FULL") {
1795
+ waitTimeBeforeRetry = getRandomNumber(0, waitTimeBeforeRetry);
1796
+ }
1514
1797
  for (const retrierError of retrier.ErrorEquals) {
1515
1798
  const isErrorMatch = retrierError === error.name;
1516
1799
  const isErrorWildcard = retrierError === WILDCARD_ERROR;
@@ -1520,7 +1803,7 @@ var StateExecutor = class {
1520
1803
  if (this.retrierAttempts[i] >= maxAttempts)
1521
1804
  return { shouldRetry: false };
1522
1805
  this.retrierAttempts[i]++;
1523
- return { shouldRetry: true, waitTimeBeforeRetry };
1806
+ return { shouldRetry: true, waitTimeBeforeRetry, retrierIndex: i };
1524
1807
  }
1525
1808
  }
1526
1809
  }
@@ -1548,7 +1831,7 @@ var StateExecutor = class {
1548
1831
  Cause: error.message
1549
1832
  };
1550
1833
  const resultPath = catcher.ResultPath;
1551
- return { nextState, errorOutput, resultPath };
1834
+ return { nextState, errorOutput, resultPath, catcherIndex: i };
1552
1835
  }
1553
1836
  }
1554
1837
  }
@@ -1622,8 +1905,7 @@ var StateExecutor = class {
1622
1905
  const waitStateAction = new WaitStateAction(stateDefinition, stateName);
1623
1906
  const executionResult = await waitStateAction.execute(input, context, {
1624
1907
  waitTimeOverrideOption,
1625
- abortSignal: options.abortSignal,
1626
- rootAbortSignal: options.runOptions?._rootAbortSignal
1908
+ abortSignal: options.abortSignal
1627
1909
  });
1628
1910
  return executionResult;
1629
1911
  }
@@ -1708,6 +1990,9 @@ var EventLogger = class {
1708
1990
  break;
1709
1991
  case "StateEntered":
1710
1992
  case "StateExited":
1993
+ case "StateFailed":
1994
+ case "StateRetried":
1995
+ case "StateCaught":
1711
1996
  event.index = index;
1712
1997
  this.dispatch(event);
1713
1998
  break;
@@ -1752,7 +2037,12 @@ var EventLogger = class {
1752
2037
  this.close();
1753
2038
  }
1754
2039
  dispatchExecutionFailedEvent(error) {
1755
- this.dispatch({ type: "ExecutionFailed", timestamp: Date.now(), Error: error.name, Cause: error.message });
2040
+ this.dispatch({
2041
+ type: "ExecutionFailed",
2042
+ timestamp: Date.now(),
2043
+ Error: error.name,
2044
+ Cause: error.cause ?? error.message
2045
+ });
1756
2046
  this.close();
1757
2047
  }
1758
2048
  dispatchExecutionAbortedEvent() {
@@ -1777,6 +2067,31 @@ var EventLogger = class {
1777
2067
  state: { name: stateName, type: stateType, input, output }
1778
2068
  });
1779
2069
  }
2070
+ dispatchStateFailedEvent(stateName, stateType, input, error) {
2071
+ this.dispatch({
2072
+ type: "StateFailed",
2073
+ timestamp: Date.now(),
2074
+ state: { name: stateName, type: stateType, input },
2075
+ Error: error.name,
2076
+ Cause: error.cause ?? error.message
2077
+ });
2078
+ }
2079
+ dispatchStateRetriedEvent(stateName, stateType, input, retrier, retryAttempt) {
2080
+ this.dispatch({
2081
+ type: "StateRetried",
2082
+ timestamp: Date.now(),
2083
+ state: { name: stateName, type: stateType, input },
2084
+ retry: { retrier, attempt: retryAttempt }
2085
+ });
2086
+ }
2087
+ dispatchStateCaughtEvent(stateName, stateType, input, catcher) {
2088
+ this.dispatch({
2089
+ type: "StateCaught",
2090
+ timestamp: Date.now(),
2091
+ state: { name: stateName, type: stateType, input },
2092
+ catch: { catcher }
2093
+ });
2094
+ }
1780
2095
  dispatchMapIterationStartedEvent(event, index, mapStateName, mapStateRawInput) {
1781
2096
  this.dispatch({
1782
2097
  ...event,
@@ -1852,7 +2167,7 @@ var StateMachine = class {
1852
2167
  * These options also apply to state machines defined in the `Iterator` field of `Map` states and in the `Branches` field of `Parallel` states.
1853
2168
  */
1854
2169
  constructor(definition, stateMachineOptions) {
1855
- if (!stateMachineOptions?.validationOptions?._noValidate) {
2170
+ if (!stateMachineOptions?.validationOptions?.noValidate) {
1856
2171
  const { isValid, errorsText } = (0, import_asl_validator.default)(definition, {
1857
2172
  checkArn: true,
1858
2173
  checkPaths: true,
@@ -1883,6 +2198,15 @@ var StateMachine = class {
1883
2198
  run(input, options) {
1884
2199
  const abortController = new AbortController();
1885
2200
  const eventLogger = new EventLogger();
2201
+ let rootSignalAbortHandler;
2202
+ if (options?._rootAbortSignal) {
2203
+ rootSignalAbortHandler = () => abortController.abort();
2204
+ if (options._rootAbortSignal.aborted) {
2205
+ rootSignalAbortHandler();
2206
+ } else {
2207
+ options._rootAbortSignal.addEventListener("abort", rootSignalAbortHandler);
2208
+ }
2209
+ }
1886
2210
  let onAbortHandler;
1887
2211
  const settleOnAbort = new Promise((resolve, reject) => {
1888
2212
  if (options?.noThrowOnAbort) {
@@ -1920,6 +2244,7 @@ var StateMachine = class {
1920
2244
  },
1921
2245
  () => {
1922
2246
  abortController.signal.removeEventListener("abort", onAbortHandler);
2247
+ options?._rootAbortSignal?.removeEventListener("abort", rootSignalAbortHandler);
1923
2248
  clearTimeout(timeoutId);
1924
2249
  }
1925
2250
  );