-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support jsonata expressions (#162)
feat: support new fields for variables chore: bump asl-path-validator version chore: npm audit fix
- Loading branch information
Showing
21 changed files
with
1,584 additions
and
694 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"Comment": "QueryLanguage is JSONata but has JSONPath fields", | ||
"StartAt": "EmptyState", | ||
"QueryLanguage": "JSONata", | ||
"States": { | ||
"EmptyState": { | ||
"Type": "Pass", | ||
"Parameters": ["abc"], | ||
"ResultPath": "$.emptyState", | ||
"End": true | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
src/__tests__/definitions/invalid-jsonata-path-fields.asl.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"Comment": "Incorrectly has JSONPath fields on JSONata states", | ||
"StartAt": "Verification", | ||
"States": { | ||
"Verification": { | ||
"Type": "Parallel", | ||
"QueryLanguage": "JSONata", | ||
"Branches": [ | ||
{ | ||
"StartAt": "Check Identity", | ||
"States": { | ||
"Check Identity": { | ||
"Type": "Pass", | ||
"QueryLanguage": "JSONata", | ||
"End": true, | ||
"OutputPath": "$.foo" | ||
} | ||
} | ||
}, | ||
{ | ||
"StartAt": "Check Address", | ||
"States": { | ||
"Check Address": { | ||
"Type": "Pass", | ||
"QueryLanguage": "JSONata", | ||
"End": true, | ||
"Output": { | ||
"isAddressValid": "{% $not(null in $each($states.input.data.address, function($v) { $length($trim($v)) > 0 ? $v : null })) %}" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"Assign": { | ||
"inputPayload": "{% $states.context.Execution.Input %}", | ||
"isCustomerValid": "{% $states.result.isIdentityValid and $states.result.isAddressValid %}" | ||
}, | ||
"Next": "Approve or Deny?" | ||
}, | ||
"Approve or Deny?": { | ||
"Type": "Choice", | ||
"QueryLanguage": "JSONata", | ||
"Choices": [ | ||
{ | ||
"Next": "Add Account", | ||
"Condition": "{% $isCustomerValid %}" | ||
} | ||
], | ||
"Default": "Deny Message" | ||
}, | ||
"Add Account": { | ||
"Type": "Task", | ||
"QueryLanguage": "JSONata", | ||
"Resource": "arn:aws:states:::dynamodb:putItem", | ||
"Arguments": { | ||
"TableName": "${AccountsTable}", | ||
"Item": { | ||
"PK": { | ||
"S": "{% $uuid() %}" | ||
}, | ||
"email": { | ||
"S": "{% $inputPayload.data.identity.email %}" | ||
}, | ||
"name": { | ||
"S": "{% $inputPayload.data.firstname & ' ' & $inputPayload.data.lastname %}" | ||
}, | ||
"address": { | ||
"S": "{% $join($each($inputPayload.data.address, function($v) { $v }), ', ') %}" | ||
}, | ||
"timestamp": { | ||
"S": "{% $now() %}" | ||
} | ||
} | ||
}, | ||
"Next": "Home Insurance Interests" | ||
}, | ||
"Home Insurance Interests": { | ||
"Type": "Task", | ||
"QueryLanguage": "JSONata", | ||
"Resource": "arn:aws:states:::sqs:sendMessage", | ||
"Arguments": { | ||
"QueueUrl": "${HomeInsuranceInterestQueueArn}", | ||
"MessageBody": "{% ($e := $inputPayload.data.identity.email; $n := $inputPayload.data.firstname & ' ' & $inputPayload.data.lastname; $inputPayload.data.interests[category = 'home']{'customer': $n, 'email': $e, 'totalAssetValue': $sum(estimatedValue), category: {type: yearBuilt}}) %}" | ||
}, | ||
"Next": "Approved Message" | ||
}, | ||
"Approved Message": { | ||
"Type": "Task", | ||
"Resource": "arn:aws:states:::sns:publish", | ||
"Parameters": { | ||
"TopicArn": "arn:aws:sns:us-east-1:123456789012:CustomerNotifications", | ||
"Message.$": "States.Format('Hello {}, your application has been approved.', $inputPayload.data.firstname)" | ||
}, | ||
"End": true | ||
}, | ||
"Deny Message": { | ||
"Type": "Task", | ||
"Resource": "arn:aws:states:::sns:publish", | ||
"Parameters": { | ||
"TopicArn": "${SendCustomerNotificationSNSTopicArn}", | ||
"Message.$": "States.Format('Hello {}, your application has been denied because validation of provided data failed', $inputPayload.data.firstname)" | ||
}, | ||
"End": true | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/__tests__/definitions/invalid-variable-result-path.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"Comment": "ResultPath cannot contain a variable", | ||
"StartAt": "StepOne", | ||
"States": { | ||
"StepOne": { | ||
"Type": "Pass", | ||
"Assign": { | ||
"foo": "bar" | ||
}, | ||
"Next": "Fin" | ||
}, | ||
"Fin": { | ||
"Type": "Task", | ||
"Resource": "arn:aws:lambda:region-1:1234567890:function:InvalidResultPath", | ||
"ResultPath": "$foo", | ||
"End": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{ | ||
"Comment": "This is a state machine for account application service", | ||
"StartAt": "Verification", | ||
"States": { | ||
"Verification": { | ||
"Type": "Parallel", | ||
"QueryLanguage": "JSONata", | ||
"Branches": [ | ||
{ | ||
"StartAt": "Check Identity", | ||
"States": { | ||
"Check Identity": { | ||
"Type": "Pass", | ||
"QueryLanguage": "JSONata", | ||
"End": true, | ||
"Output": { | ||
"isIdentityValid": "{% $match($states.input.data.identity.email, /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/) and $match($states.input.data.identity.ssn, /^(\\d{3}-?\\d{2}-?\\d{4}|XXX-XX-XXXX)$/) %}" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"StartAt": "Check Address", | ||
"States": { | ||
"Check Address": { | ||
"Type": "Pass", | ||
"QueryLanguage": "JSONata", | ||
"End": true, | ||
"Output": { | ||
"isAddressValid": "{% $not(null in $each($states.input.data.address, function($v) { $length($trim($v)) > 0 ? $v : null })) %}" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"Assign": { | ||
"inputPayload": "{% $states.context.Execution.Input %}", | ||
"isCustomerValid": "{% $states.result.isIdentityValid and $states.result.isAddressValid %}" | ||
}, | ||
"Next": "Approve or Deny?" | ||
}, | ||
"Approve or Deny?": { | ||
"Type": "Choice", | ||
"QueryLanguage": "JSONata", | ||
"Choices": [ | ||
{ | ||
"Next": "Add Account", | ||
"Condition": "{% $isCustomerValid %}" | ||
} | ||
], | ||
"Default": "Deny Message" | ||
}, | ||
"Add Account": { | ||
"Type": "Task", | ||
"QueryLanguage": "JSONata", | ||
"Resource": "arn:aws:states:::dynamodb:putItem", | ||
"Arguments": { | ||
"TableName": "${AccountsTable}", | ||
"Item": { | ||
"PK": { | ||
"S": "{% $uuid() %}" | ||
}, | ||
"email": { | ||
"S": "{% $inputPayload.data.identity.email %}" | ||
}, | ||
"name": { | ||
"S": "{% $inputPayload.data.firstname & ' ' & $inputPayload.data.lastname %}" | ||
}, | ||
"address": { | ||
"S": "{% $join($each($inputPayload.data.address, function($v) { $v }), ', ') %}" | ||
}, | ||
"timestamp": { | ||
"S": "{% $now() %}" | ||
} | ||
} | ||
}, | ||
"Next": "Home Insurance Interests" | ||
}, | ||
"Home Insurance Interests": { | ||
"Type": "Task", | ||
"QueryLanguage": "JSONata", | ||
"Resource": "arn:aws:states:::sqs:sendMessage", | ||
"Arguments": { | ||
"QueueUrl": "${HomeInsuranceInterestQueueArn}", | ||
"MessageBody": "{% ($e := $inputPayload.data.identity.email; $n := $inputPayload.data.firstname & ' ' & $inputPayload.data.lastname; $inputPayload.data.interests[category = 'home']{'customer': $n, 'email': $e, 'totalAssetValue': $sum(estimatedValue), category: {type: yearBuilt}}) %}" | ||
}, | ||
"Next": "Approved Message" | ||
}, | ||
"Approved Message": { | ||
"Type": "Task", | ||
"Resource": "arn:aws:states:::sns:publish", | ||
"Parameters": { | ||
"TopicArn": "arn:aws:sns:us-east-1:123456789012:CustomerNotifications", | ||
"Message.$": "States.Format('Hello {}, your application has been approved.', $inputPayload.data.firstname)" | ||
}, | ||
"End": true | ||
}, | ||
"Deny Message": { | ||
"Type": "Task", | ||
"Resource": "arn:aws:states:::sns:publish", | ||
"Parameters": { | ||
"TopicArn": "${SendCustomerNotificationSNSTopicArn}", | ||
"Message.$": "States.Format('Hello {}, your application has been denied because validation of provided data failed', $inputPayload.data.firstname)" | ||
}, | ||
"End": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.