@justworkflowit/cdk-constructs 0.0.192 → 0.0.194

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.
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
4
+ const justWorkflowItConstructs_1 = require("../../constructs/justWorkflowItConstructs");
5
+ describe('JustWorkflowItConstructs', () => {
6
+ const validWorkflowDefinition = JSON.stringify({
7
+ workflowName: 'validWorkflow',
8
+ steps: [
9
+ {
10
+ name: 'step1',
11
+ retries: 2,
12
+ timeoutSeconds: 1000,
13
+ transitionToStep: null,
14
+ integrationDetails: {
15
+ type: 'testIntegration',
16
+ inputDefinition: {
17
+ $ref: '#/definitions/step1Input',
18
+ },
19
+ outputDefinition: {
20
+ $ref: '#/definitions/step1Output',
21
+ },
22
+ },
23
+ },
24
+ ],
25
+ definitions: {
26
+ step1Input: {
27
+ type: 'object',
28
+ properties: {
29
+ inputProperty: {
30
+ type: 'string',
31
+ },
32
+ },
33
+ required: ['inputProperty'],
34
+ additionalProperties: false,
35
+ },
36
+ step1Output: {
37
+ type: 'object',
38
+ properties: {
39
+ outputProperty: {
40
+ type: 'string',
41
+ },
42
+ },
43
+ required: ['outputProperty'],
44
+ additionalProperties: false,
45
+ },
46
+ },
47
+ });
48
+ test('should create construct with valid workflow definition', () => {
49
+ const app = new aws_cdk_lib_1.App();
50
+ const stack = new aws_cdk_lib_1.Stack(app, 'TestStack');
51
+ expect(() => {
52
+ new justWorkflowItConstructs_1.JustWorkflowItConstructs(stack, {
53
+ disambiguator: 'test',
54
+ organizationId: 'org123',
55
+ workflowDefinitions: [validWorkflowDefinition],
56
+ });
57
+ }).not.toThrow();
58
+ });
59
+ test('should reject construct with invalid workflow definition at synth time', () => {
60
+ const app = new aws_cdk_lib_1.App();
61
+ const stack = new aws_cdk_lib_1.Stack(app, 'TestStack');
62
+ const invalidWorkflowDefinition = JSON.stringify({
63
+ workflowName: 'invalidWorkflow',
64
+ steps: [
65
+ {
66
+ // Missing required 'name' field
67
+ retries: 2,
68
+ timeoutSeconds: 1000,
69
+ transitionToStep: null,
70
+ integrationDetails: {
71
+ type: 'testIntegration',
72
+ },
73
+ },
74
+ ],
75
+ definitions: {},
76
+ });
77
+ expect(() => {
78
+ new justWorkflowItConstructs_1.JustWorkflowItConstructs(stack, {
79
+ disambiguator: 'test',
80
+ organizationId: 'org123',
81
+ workflowDefinitions: [invalidWorkflowDefinition],
82
+ });
83
+ }).toThrow(/Invalid workflow definition at index 0/);
84
+ });
85
+ test('should reject construct with malformed JSON workflow definition', () => {
86
+ const app = new aws_cdk_lib_1.App();
87
+ const stack = new aws_cdk_lib_1.Stack(app, 'TestStack');
88
+ const malformedJson = '{ "workflowName": "invalid", "steps": [';
89
+ expect(() => {
90
+ new justWorkflowItConstructs_1.JustWorkflowItConstructs(stack, {
91
+ disambiguator: 'test',
92
+ organizationId: 'org123',
93
+ workflowDefinitions: [malformedJson],
94
+ });
95
+ }).toThrow(/Invalid workflow definition at index 0/);
96
+ });
97
+ test('should validate multiple workflow definitions and report correct index on failure', () => {
98
+ const app = new aws_cdk_lib_1.App();
99
+ const stack = new aws_cdk_lib_1.Stack(app, 'TestStack');
100
+ const invalidAtIndex1 = JSON.stringify({
101
+ workflowName: 'invalid',
102
+ // Missing steps
103
+ });
104
+ expect(() => {
105
+ new justWorkflowItConstructs_1.JustWorkflowItConstructs(stack, {
106
+ disambiguator: 'test',
107
+ organizationId: 'org123',
108
+ workflowDefinitions: [
109
+ validWorkflowDefinition,
110
+ invalidAtIndex1,
111
+ validWorkflowDefinition,
112
+ ],
113
+ });
114
+ }).toThrow(/Invalid workflow definition at index 1/);
115
+ });
116
+ test('should reject workflow with array index that may not exist', () => {
117
+ const app = new aws_cdk_lib_1.App();
118
+ const stack = new aws_cdk_lib_1.Stack(app, 'TestStack');
119
+ const workflowWithArrayRef = JSON.stringify({
120
+ workflowName: 'arrayRefWorkflow',
121
+ steps: [
122
+ {
123
+ name: 'getItems',
124
+ retries: 2,
125
+ timeoutSeconds: 1000,
126
+ transitionToStep: 'processItem',
127
+ integrationDetails: {
128
+ type: 'getItemsIntegration',
129
+ inputDefinition: {
130
+ $ref: '#/definitions/getItemsInput',
131
+ },
132
+ outputDefinition: {
133
+ $ref: '#/definitions/getItemsOutput',
134
+ },
135
+ },
136
+ },
137
+ {
138
+ name: 'processItem',
139
+ retries: 2,
140
+ timeoutSeconds: 1000,
141
+ transitionToStep: null,
142
+ integrationDetails: {
143
+ type: 'processItemIntegration',
144
+ inputDefinition: {
145
+ $ref: '#/definitions/processItemInput',
146
+ },
147
+ outputDefinition: {
148
+ $ref: '#/definitions/processItemOutput',
149
+ },
150
+ inputTransformer: {
151
+ fieldset: [
152
+ {
153
+ from: 'getItemsOutput.items[0].id',
154
+ to: 'itemId',
155
+ },
156
+ ],
157
+ },
158
+ },
159
+ },
160
+ ],
161
+ definitions: {
162
+ getItemsInput: {
163
+ type: 'object',
164
+ properties: {},
165
+ additionalProperties: false,
166
+ },
167
+ getItemsOutput: {
168
+ type: 'object',
169
+ properties: {
170
+ items: {
171
+ type: 'array',
172
+ items: {
173
+ type: 'object',
174
+ properties: {
175
+ id: { type: 'string' },
176
+ },
177
+ },
178
+ },
179
+ },
180
+ required: ['items'],
181
+ additionalProperties: false,
182
+ },
183
+ processItemInput: {
184
+ type: 'object',
185
+ properties: {
186
+ itemId: { type: 'string' },
187
+ },
188
+ required: ['itemId'],
189
+ additionalProperties: false,
190
+ },
191
+ processItemOutput: {
192
+ type: 'object',
193
+ properties: {},
194
+ additionalProperties: false,
195
+ },
196
+ },
197
+ });
198
+ expect(() => {
199
+ new justWorkflowItConstructs_1.JustWorkflowItConstructs(stack, {
200
+ disambiguator: 'test',
201
+ organizationId: 'org123',
202
+ workflowDefinitions: [workflowWithArrayRef],
203
+ });
204
+ }).toThrow(/Invalid workflow definition at index 0.*items\[0\]/);
205
+ });
206
+ });
@@ -45,9 +45,38 @@ const aws_s3_1 = require("aws-cdk-lib/aws-s3");
45
45
  const aws_s3_deployment_1 = require("aws-cdk-lib/aws-s3-deployment");
46
46
  const path = __importStar(require("path"));
47
47
  const uuid_1 = require("uuid");
48
+ const engine_1 = require("@justworkflowit/engine");
48
49
  class JustWorkflowItConstructs extends constructs_1.Construct {
49
50
  constructor(scope, props) {
50
51
  super(scope, `${JustWorkflowItConstructs.CONSTRUCT_ID_PREFIX}${props.disambiguator}`);
52
+ // Validate all workflow definitions at CDK synth time
53
+ props.workflowDefinitions.forEach((definition, index) => {
54
+ try {
55
+ // Parse the workflow to extract integration types
56
+ const parsedWorkflow = JSON.parse(definition);
57
+ const integrationTypes = new Set();
58
+ if (parsedWorkflow.steps && Array.isArray(parsedWorkflow.steps)) {
59
+ parsedWorkflow.steps.forEach((step) => {
60
+ if (step?.integrationDetails?.type) {
61
+ integrationTypes.add(step.integrationDetails.type);
62
+ }
63
+ });
64
+ }
65
+ // Create dummy step executors for validation purposes
66
+ const dummyExecutors = Array.from(integrationTypes).map((type) => ({
67
+ type,
68
+ execute: async () => ({ status: 'success', payload: {} }),
69
+ }));
70
+ // This will throw if the workflow definition is invalid
71
+ new engine_1.JustWorkflowItEngine({
72
+ workflowDefinition: definition,
73
+ stepExecutors: dummyExecutors,
74
+ });
75
+ }
76
+ catch (error) {
77
+ throw new Error(`Invalid workflow definition at index ${index}: ${error instanceof Error ? error.message : String(error)}`);
78
+ }
79
+ });
51
80
  const secretName = '/justworkflowit/api/authToken';
52
81
  const secret = new aws_secretsmanager_1.Secret(this, 'JustWorkflowItAuthTokenSecret', {
53
82
  secretName,
@@ -72,7 +101,7 @@ class JustWorkflowItConstructs extends constructs_1.Construct {
72
101
  });
73
102
  const integrationLambda = new aws_lambda_nodejs_1.NodejsFunction(this, 'JustWorkflowItDefinitionDeployerLambda', {
74
103
  functionName: `JustWorkflowItDefinitionDeployer-${props.disambiguator}`,
75
- entry: path.join(__dirname, '../lambda/definitionDeployerLambda.js'),
104
+ entry: path.join(__dirname, '../lambda/definitionDeployerLambda.ts'),
76
105
  handler: 'handler',
77
106
  runtime: aws_lambda_1.Runtime.NODEJS_20_X,
78
107
  timeout: aws_cdk_lib_1.Duration.minutes(5),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justworkflowit/cdk-constructs",
3
3
  "description": "",
4
- "version": "0.0.192",
4
+ "version": "0.0.194",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "publishConfig": {
@@ -24,11 +24,11 @@
24
24
  "dependencies": {
25
25
  "@aws-sdk/client-s3": "^3.842.0",
26
26
  "@justworkflowit/api-client": "*",
27
+ "@justworkflowit/engine": "^0.0.74",
27
28
  "aws-cdk-lib": "^2.0.0",
28
29
  "constructs": "^10.0.0"
29
30
  },
30
31
  "devDependencies": {
31
- "@justworkflowit/engine": "^0.0.72",
32
32
  "@types/jest": "^29.5.12",
33
33
  "@types/node": "^20.12.5",
34
34
  "cdk-cli": "^1.1.0",
@@ -47,6 +47,8 @@
47
47
  "typescript-eslint": "^8.24.1"
48
48
  },
49
49
  "peerDependencies": {
50
+ "@justworkflowit/api-client": "*",
51
+ "@justworkflowit/engine": "^0.0.74",
50
52
  "aws-cdk-lib": "^2.0.0",
51
53
  "constructs": "^10.0.0"
52
54
  }