arazzo-runner 0.0.21 → 0.0.23

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
@@ -210,17 +210,27 @@ You will need to provide inputs for your clientId and clientSecret:
210
210
 
211
211
  This can handle the encoding and sending of:
212
212
 
213
- - application/json
214
- - application/xml
215
- - text/xml
216
- - text/html
217
- - text/plain
218
- - application/x-www-form-urlencoded
219
- - multipart/form-data
220
- - application/octet-stream
213
+ - application/json
214
+ - application/xml
215
+ - text/xml
216
+ - text/html
217
+ - text/plain
218
+ - application/x-www-form-urlencoded
219
+ - multipart/form-data
220
+ - application/octet-stream
221
221
 
222
222
  For anything outside of this range, it will attempt to encode as JSON if you specify an object, otherwise it will encode as plain text.
223
223
 
224
+ ## Response Bodies
225
+
226
+ This can handle response bodies of:
227
+
228
+ - application/json
229
+ - application/xml
230
+ - text/xml
231
+ - text/html
232
+ - text/plain
233
+
224
234
  ## Logging And Reporting
225
235
 
226
236
  ### Logging
@@ -254,7 +264,3 @@ Work on Reporting still needs completeing.
254
264
  ### PathOperation
255
265
 
256
266
  Accessing an OpenAPI operation by Operation Path `'{$sourceDescriptions.petstoreDescription.url}#/paths/~1pet~1findByStatus/get'` does not work currently
257
-
258
- ### Non application/json Responses
259
-
260
- Responses that do not conform to application/json do not work
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "arazzo-runner",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "A runner to run through Arazzo Document workflows",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "mocha --config './test/.mocharc.js'",
8
+ "test-specific": "mocha --config './test/.mocharc.js' --grep 'runs a dependsOn workflow belonging to another arazzo document first'",
8
9
  "test-coverage": "nyc mocha --config './test/.mocharc.js'",
9
10
  "prepare": "husky",
10
11
  "start": "node cli.js"
package/src/Arazzo.js CHANGED
@@ -127,7 +127,8 @@ class Arazzo extends Document {
127
127
  if (this.workflow.dependsOn) {
128
128
  await this.runDependsOnWorkflows();
129
129
 
130
- this.workflow = workflow;
130
+ const currentContext = this.executionStack.current;
131
+ await this.restoreContextFromRetry(currentContext);
131
132
  }
132
133
 
133
134
  // this.inputs = await this.inputFile.getWorkflowInputs(
@@ -204,11 +205,41 @@ class Arazzo extends Document {
204
205
  this.logger.notice("Running Workflows from dependsOn");
205
206
 
206
207
  for await (const workflowId of this.workflow.dependsOn) {
207
- const workflowIndex = this.findWorkflowIndexByWorkflowId(workflowId);
208
+ let workflowIdArr = workflowId?.split(".") || [];
209
+ let workflowIndex = -1;
210
+ if (workflowIdArr.length !== 1) {
211
+ const actualWorkflowId = workflowIdArr.at(-1);
212
+
213
+ const joinedoperationOrWorkflowPointer = `${workflowIdArr[0]}.${workflowIdArr[1]}`;
214
+
215
+ const sourceDescription = this.expression.resolveExpression(
216
+ joinedoperationOrWorkflowPointer,
217
+ );
218
+
219
+ await this.getSourceDescriptionFile(sourceDescription);
220
+ await this.sourceDescriptionFile.loadWorkflowData(this.inputFile);
221
+
222
+ workflowIndex = this.sourceDescriptionFile.findWorkflowIndexByWorkflowId(actualWorkflowId)
223
+
224
+ if (workflowIndex !== -1) {
225
+ await this.sourceDescriptionFile.runWorkflow(workflowIndex);
226
+ const sourceDesc = this.expression.context.sourceDescriptions[this.sourceDescriptionFile.name];
227
+ if (!sourceDesc[actualWorkflowId]) {
228
+ if (this.sourceDescriptionFile.expression?.context?.workflows?.[actualWorkflowId]?.outputs) {
229
+ Object.assign(sourceDesc, { [actualWorkflowId]: { outputs: this.sourceDescriptionFile.expression.context.workflows[actualWorkflowId].outputs } });
230
+ this.expression.context.sourceDescriptions[this.sourceDescriptionFile.name] = sourceDesc;
231
+ }
232
+ }
233
+ }
234
+ } else {
235
+ workflowIndex = this.findWorkflowIndexByWorkflowId(workflowId);
208
236
 
209
- if (workflowIndex !== -1) {
210
- await this.runWorkflow(workflowIndex);
237
+ if (workflowIndex !== -1) {
238
+ await this.runWorkflow(workflowIndex);
239
+ }
211
240
  }
241
+
242
+
212
243
  }
213
244
 
214
245
  this.logger.success("All Workflows from dependsOn have run");
@@ -806,25 +837,9 @@ class Arazzo extends Document {
806
837
  async loadOperationData() {
807
838
  this.sourceDescription = this.getOperationIdSourceDescription();
808
839
 
809
- if (!this.loadedSourceDescriptions[this.sourceDescription.name]) {
810
- this.logger.notice(
811
- `Getting Source Description for: ${this.sourceDescription.name}`,
812
- );
813
-
814
- this.sourceDescriptionFile = await this.docFactory.buildDocument(
815
- this.sourceDescription.type,
816
- this.sourceDescription.url,
817
- this.sourceDescription.name,
818
- { logger: this.logger, config: this.config },
819
- );
820
-
821
- Object.assign(this.loadedSourceDescriptions, {
822
- [this.sourceDescription.name]: true,
823
- });
824
- }
840
+ await this.getSourceDescriptionFile(this.sourceDescription)
825
841
 
826
842
  if (this.isAnOperationId) {
827
- // this.logger.notice(`Getting OperationId: ${this.step.operationId}`);
828
843
  let operationId = this.step.operationId;
829
844
 
830
845
  operationId = operationId.split(".").at(-1);
@@ -843,6 +858,33 @@ class Arazzo extends Document {
843
858
  }
844
859
  }
845
860
 
861
+ async getSourceDescriptionFile(sourceDescription) {
862
+ if (!this.loadedSourceDescriptions[sourceDescription.name]) {
863
+ this.logger.notice(
864
+ `Getting Source Description for: ${sourceDescription.name}`,
865
+ );
866
+
867
+ this.sourceDescriptionFile = await this.docFactory.buildDocument(
868
+ sourceDescription.type,
869
+ sourceDescription.url,
870
+ sourceDescription.name,
871
+ { logger: this.logger, config: this.config },
872
+ );
873
+
874
+ Object.assign(this.loadedSourceDescriptions, {
875
+ [sourceDescription.name]: { loaded: true, filePath: this.sourceDescriptionFile.filePath },
876
+
877
+ });
878
+ } else {
879
+ this.sourceDescriptionFile = await this.docFactory.buildDocument(
880
+ sourceDescription.type,
881
+ this.loadedSourceDescriptions[this.sourceDescription.name].filePath,
882
+ sourceDescription.name,
883
+ { logger: this.logger, config: this.config },
884
+ );
885
+ }
886
+ }
887
+
846
888
  /**
847
889
  * @private
848
890
  * @returns
package/src/DocFactory.js CHANGED
@@ -4,7 +4,7 @@ const Arazzo = require("./Arazzo");
4
4
  const OpenAPI = require("./OpenAPI");
5
5
 
6
6
  class DocumentFactory {
7
- constructor() {}
7
+ constructor() { }
8
8
 
9
9
  /**
10
10
  * Tests whether a string is a URL or not
@@ -40,7 +40,7 @@ class DocumentFactory {
40
40
 
41
41
  if (this.isUrl(path)) {
42
42
  await document.loadDocument();
43
- } else document.setMainArazzo();
43
+ } else document.setFilePath();
44
44
 
45
45
  return document;
46
46
  }
package/src/Document.js CHANGED
@@ -22,6 +22,10 @@ class Document {
22
22
  this.config = config;
23
23
  }
24
24
 
25
+ setFilePath() {
26
+ this.filePath = path.resolve(this.url);
27
+ }
28
+
25
29
  async loadDocument() {
26
30
  let headers = new Headers();
27
31
  let fetchURL = new URL(this.url);
package/src/Operation.js CHANGED
@@ -269,9 +269,20 @@ class Operation {
269
269
 
270
270
  this.expression.addToContext("response.body", json);
271
271
  } else {
272
- const body = await response.body;
272
+ if (response.headers.has("Content-Type") && ['application/xml', 'text/xml', 'text/plain', 'text/html'].includes(response.headers.get("Content-Type"))) {
273
+ const data = await response?.text().catch(err => {
274
+ this.logger.error(
275
+ `Error trying to resolve ${this.step.stepId} outputs`,
276
+ );
277
+ throw new Error(err);
278
+ })
279
+
280
+ this.expression.addToContext("response.body", data);
281
+ } else {
282
+ const body = await response.body;
283
+ this.expression.addToContext("response.body", body);
284
+ }
273
285
 
274
- this.expression.addToContext("response.body", body);
275
286
  }
276
287
  }
277
288