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.
package/README.md CHANGED
@@ -25,6 +25,7 @@ This package lets you run AWS Step Functions state machines completely locally,
25
25
  ## Table of contents
26
26
 
27
27
  - [Features](#features)
28
+ - [Use cases](#use-cases)
28
29
  - [Installation](#installation)
29
30
  - [Importing](#importing)
30
31
  - [Node.js](#nodejs)
@@ -50,6 +51,16 @@ This package lets you run AWS Step Functions state machines completely locally,
50
51
 
51
52
  To see the list of features defined in the specification that have full support, partial support, or no support, refer to [this document](/docs/feature-support.md).
52
53
 
54
+ ## Use cases
55
+
56
+ Why would you want to use this package? Below is a non-exhaustive list of use cases for `aws-local-stepfunctions`:
57
+
58
+ - Testing state machines changes locally before deploying them to AWS.
59
+ - Testing the integration between a state machine and the Lambda functions associated with it in `Task` states.
60
+ - Debugging the code of associated Lambda functions interactively using the [`Task` state resource override feature](/docs/feature-support.md#task-state-resource-override).
61
+ - Debugging a state machine by using the [event logs feature](/docs/feature-support.md#execution-event-logs), to better understand the transitions between states and how data flows between them.
62
+ - Running state machines in the browser (not possible with [AWS Step Functions Local](https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local.html)).
63
+
53
64
  ## Installation
54
65
 
55
66
  ```sh
@@ -103,6 +114,8 @@ The constructor takes the following parameters:
103
114
  - `validationOptions?`: An object that specifies how the definition should be validated.
104
115
  - `checkPaths`: If set to `false`, won't validate JSONPaths.
105
116
  - `checkArn`: If set to `false`, won't validate ARN syntax in `Task` states.
117
+ - `noValidate`: If set to `true`, will skip validation of the definition entirely.
118
+ > NOTE: Use this option at your own risk, there are no guarantees when passing an invalid or non-standard definition to the state machine. Running it might result in undefined/unsupported behavior.
106
119
  - `awsConfig?`: An object that specifies the [AWS region and credentials](/docs/feature-support.md#providing-aws-credentials-and-region-to-execute-lambda-functions-specified-in-task-states) to use when invoking a Lambda function in a `Task` state. If not set, the AWS config will be resolved based on the [credentials provider chain](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html) of the AWS SDK for JavaScript V3. You don't need to use this option if you have a [shared config/credentials file](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html) (for example, if you have the [AWS CLI](https://aws.amazon.com/cli/) installed) or if you use a local override for all of your `Task` states.
107
120
  - `region`: The AWS region where the Lambda functions are created.
108
121
  - `credentials`: An object that specifies which type of credentials to use.
@@ -136,11 +149,7 @@ const stateMachine = new StateMachine(machineDefinition, {
136
149
 
137
150
  ### `StateMachine.run(input[, options])`
138
151
 
139
- Runs the state machine with the given `input` parameter and returns an object with the following properties:
140
-
141
- - `result`: A `Promise` that resolves with the result of the execution once it terminates.
142
- - `abort`: A function that takes no parameters and doesn't return any value. If called, [aborts the execution](/docs/feature-support.md#abort-a-running-execution) and throws an `ExecutionAbortedError`, unless the `noThrowOnAbort` option is set.
143
- - `eventLogs`: An `AsyncGenerator` that [produces a log of events](/docs/feature-support.md#execution-event-logs) as the execution runs. To learn more about the events, their type, and their format, see the [following document](/docs/execution-event-logs.md).
152
+ Runs the state machine with the given `input`.
144
153
 
145
154
  Each execution is independent of all others, meaning that you can concurrently call this method as many times as needed, without worrying about race conditions.
146
155
 
@@ -154,6 +163,14 @@ Each execution is independent of all others, meaning that you can concurrently c
154
163
  - `noThrowOnAbort?`: If this option is set to `true`, aborting the execution will simply return `null` as result instead of throwing.
155
164
  - `context?`: An object that will be used as the [Context Object](https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html) for the execution. If not passed, the Context Object will default to an empty object. This option is useful to mock the Context Object in case your definition references it in a JSONPath.
156
165
 
166
+ #### Return value
167
+
168
+ Returns an object that has the following properties:
169
+
170
+ - `result`: A `Promise` that resolves with the result of the execution, if it ends successfully.
171
+ - `abort`: A function that takes no parameters and doesn't return any value. If called, [aborts the execution](/docs/feature-support.md#abort-a-running-execution) and throws an `ExecutionAbortedError`, unless the `noThrowOnAbort` option is set.
172
+ - `eventLogs`: An `AsyncGenerator` that [produces a log of events](/docs/feature-support.md#execution-event-logs) as the execution runs. To learn more about the events, their type, and their format, see the [following document](/docs/execution-event-logs.md).
173
+
157
174
  #### Basic example:
158
175
 
159
176
  ```js
@@ -381,8 +398,12 @@ Before attempting to run the state machine with the given inputs, the state mach
381
398
 
382
399
  - JSONPath strings are valid.
383
400
  - ARNs in the `Resource` field of `Task` states are valid.
401
+ - There are no invalid fields.
402
+ - All states in the definition can be reached.
403
+
404
+ If any of these checks fail, `local-sfn` will print the validation error and exit. To partially suppress this behavior, you can pass the `--no-jsonpath-validation` option, to suppress JSONPath validation; and the `--no-arn-validation` option, to suppress ARN validation.
384
405
 
385
- If any of these two checks fail, `local-sfn` will print the validation error and exit. To suppress this behavior, you can pass the `--no-jsonpath-validation` option, to suppress JSONPath validation; and the `--no-arn-validation` option, to suppress ARN validation.
406
+ Alternatively, if you want to completely disable all validations, you can pass the `--no-validation` option. Be aware that passing this option implies no guarantees if the provided definition is invalid or contains non-standard fields: running it might result in undefined/unsupported behavior, so use at your own risk.
386
407
 
387
408
  ### Exit codes
388
409
 
@@ -38,13 +38,14 @@ var import_readline = __toESM(require("readline"), 1);
38
38
  var import_commander = require("commander");
39
39
 
40
40
  // package.json
41
- var version = "1.0.0";
41
+ var version = "1.2.0";
42
42
 
43
43
  // src/cli/ArgumentParsers.ts
44
44
  var import_fs = require("fs");
45
45
  var import_child_process = require("child_process");
46
46
 
47
47
  // src/util/index.ts
48
+ var isBrowserEnvironment = typeof window !== "undefined" && typeof window.document !== "undefined";
48
49
  function tryJSONParse(jsonStr) {
49
50
  try {
50
51
  return JSON.parse(jsonStr);
@@ -148,14 +149,15 @@ function parseInputArguments(command, value, previous = []) {
148
149
  }
149
150
 
150
151
  // src/cli/CommandHandler.ts
151
- var import_main = require("./main.node.cjs");
152
+ var import_main = require("../build/main.node.cjs");
152
153
  async function commandAction(inputs, options, command) {
153
154
  let stateMachine;
154
155
  try {
155
156
  stateMachine = new import_main.StateMachine(options.definition ?? options.definitionFile, {
156
157
  validationOptions: {
157
158
  checkPaths: options.jsonpathValidation,
158
- checkArn: options.arnValidation
159
+ checkArn: options.arnValidation,
160
+ noValidate: !options.validation
159
161
  }
160
162
  });
161
163
  } catch (error) {
@@ -244,7 +246,12 @@ Example calls:
244
246
  ).argParser((value) => parseContextFileOption(command, value))
245
247
  ).addOption(
246
248
  new import_commander.Option("--no-jsonpath-validation", "Disable validation of JSONPath strings in the state machine definition.")
247
- ).addOption(new import_commander.Option("--no-arn-validation", "Disable validation of ARNs in the state machine definition.")).argument(
249
+ ).addOption(new import_commander.Option("--no-arn-validation", "Disable validation of ARNs in the state machine definition.")).addOption(
250
+ new import_commander.Option(
251
+ "--no-validation",
252
+ "Disable validation of the state machine definition entirely. Use this option at your own risk, there are no guarantees when passing an invalid or non-standard definition to the state machine. Running it might result in undefined/unsupported behavior."
253
+ )
254
+ ).argument(
248
255
  "[inputs...]",
249
256
  "Input data for the state machine, can be any valid JSON value. Each input represents a state machine execution.\n\nWhen reading from the standard input, if the first line can be parsed as a single JSON value, then each line will be considered as an input. Otherwise, the entire standard input will be considered as a single JSON input.",
250
257
  (value, previous) => parseInputArguments(command, value, previous)