arazzo-runner 0.0.12 → 0.0.13
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/package.json +2 -1
- package/src/Arazzo.js +45 -30
- package/src/Expression.js +24 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arazzo-runner",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "A runner to run through Arazzo Document workflows",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@swaggerexpert/arazzo-runtime-expression": "^1.0.1",
|
|
41
41
|
"@swaggerexpert/json-pointer": "^2.10.2",
|
|
42
42
|
"ajv": "^8.17.1",
|
|
43
|
+
"fast-xml-parser": "^5.3.3",
|
|
43
44
|
"jsonpath": "^1.1.1",
|
|
44
45
|
"openapi-params": "^0.0.5",
|
|
45
46
|
"openapi-server-url-templating": "^1.3.0",
|
package/src/Arazzo.js
CHANGED
|
@@ -348,9 +348,9 @@ class Arazzo extends Document {
|
|
|
348
348
|
} else {
|
|
349
349
|
this.logger.verbose("Using fetch call");
|
|
350
350
|
|
|
351
|
-
this.logger.verbose(`url: ${url}`);
|
|
352
|
-
this.logger.verbose(`method: ${options.method}`);
|
|
353
|
-
this.logger.verbose("headers:");
|
|
351
|
+
this.logger.verbose(`request url: ${url}`);
|
|
352
|
+
this.logger.verbose(`request method: ${options.method}`);
|
|
353
|
+
this.logger.verbose("request headers:");
|
|
354
354
|
for (const [key, value] of options.headers.entries()) {
|
|
355
355
|
this.logger.verbose(`${key}: ${value}`);
|
|
356
356
|
}
|
|
@@ -360,6 +360,12 @@ class Arazzo extends Document {
|
|
|
360
360
|
response = await fetch(url, options);
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
+
this.logger.verbose(`received StatusCode: ${response.status}`);
|
|
364
|
+
this.logger.verbose(`received headers:`);
|
|
365
|
+
for (const [key, value] of response.headers.entries()) {
|
|
366
|
+
this.logger.verbose(`${key}: ${value}`);
|
|
367
|
+
}
|
|
368
|
+
|
|
363
369
|
if (response.headers.has("retry-after")) {
|
|
364
370
|
const retryAfter = parseRetryAfter(response.headers.get("retry-after"));
|
|
365
371
|
if (retryAfter !== null) {
|
|
@@ -504,32 +510,48 @@ class Arazzo extends Document {
|
|
|
504
510
|
* @param {*} response
|
|
505
511
|
*/
|
|
506
512
|
async dealWithResponse(response) {
|
|
513
|
+
if (
|
|
514
|
+
response.headers.has("Content-Type") &&
|
|
515
|
+
response.headers.get("Content-Type") === "application/json"
|
|
516
|
+
) {
|
|
517
|
+
const json = await response?.json().catch((err) => {
|
|
518
|
+
this.logger.error(
|
|
519
|
+
`Error trying to resolve ${this.step.stepId} outputs`,
|
|
520
|
+
);
|
|
521
|
+
throw new Error(err);
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
this.expression.addToContext("response.body", json);
|
|
525
|
+
} else {
|
|
526
|
+
const body = await response.body;
|
|
527
|
+
|
|
528
|
+
this.expression.addToContext("response.body", body);
|
|
529
|
+
}
|
|
530
|
+
|
|
507
531
|
this.doNotProcessStep = false;
|
|
508
532
|
this.alreadyProcessingOnFailure = false;
|
|
509
533
|
|
|
510
534
|
if (this.step.successCriteria) {
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
if (this.
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
this.logger.notice("Retries stopped");
|
|
520
|
-
}
|
|
535
|
+
const passedSuccessCriteria = this.hasPassedSuccessCriteria();
|
|
536
|
+
|
|
537
|
+
if (passedSuccessCriteria) {
|
|
538
|
+
this.logger.success("All criteria checks passed");
|
|
539
|
+
if (this.currentRetryRule) {
|
|
540
|
+
if (this.retryContext.doNotDeleteRetryLimits) {
|
|
541
|
+
this.retryLimits[this.currentRetryRule] = 0;
|
|
542
|
+
this.logger.notice("Retries stopped");
|
|
521
543
|
}
|
|
544
|
+
}
|
|
522
545
|
|
|
523
|
-
|
|
546
|
+
await this.dealWithPassedRule(response);
|
|
547
|
+
} else {
|
|
548
|
+
this.logger.error("Not all criteria checks passed");
|
|
549
|
+
if (this.step.onFailure) {
|
|
550
|
+
await this.dealWithFailedRule();
|
|
524
551
|
} else {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
} else {
|
|
529
|
-
throw new Error(
|
|
530
|
-
`${this.step.stepId} step of the ${this.workflow.workflowId} workflow failed the successCriteria`,
|
|
531
|
-
);
|
|
532
|
-
}
|
|
552
|
+
throw new Error(
|
|
553
|
+
`${this.step.stepId} step of the ${this.workflow.workflowId} workflow failed the successCriteria`,
|
|
554
|
+
);
|
|
533
555
|
}
|
|
534
556
|
}
|
|
535
557
|
} else {
|
|
@@ -843,14 +865,7 @@ class Arazzo extends Document {
|
|
|
843
865
|
* @private
|
|
844
866
|
* @param {*} response
|
|
845
867
|
*/
|
|
846
|
-
async dealWithStepOutputs(
|
|
847
|
-
const json = await response?.json().catch((err) => {
|
|
848
|
-
this.logger.error(`Error trying to resolve ${this.step.stepId} outputs`);
|
|
849
|
-
throw new Error(err);
|
|
850
|
-
});
|
|
851
|
-
|
|
852
|
-
this.expression.addToContext("response.body", json);
|
|
853
|
-
|
|
868
|
+
async dealWithStepOutputs() {
|
|
854
869
|
const outputs = {};
|
|
855
870
|
for (const key in this.step.outputs) {
|
|
856
871
|
const value = this.expression.resolveExpression(this.step.outputs[key]);
|
package/src/Expression.js
CHANGED
|
@@ -242,6 +242,18 @@ class Expression {
|
|
|
242
242
|
// return expression;
|
|
243
243
|
// }
|
|
244
244
|
|
|
245
|
+
/**
|
|
246
|
+
* @private
|
|
247
|
+
* @param {*} value
|
|
248
|
+
* @returns {boolean}
|
|
249
|
+
*/
|
|
250
|
+
isXML(value) {
|
|
251
|
+
return (
|
|
252
|
+
typeof value === "string" &&
|
|
253
|
+
(value.trim().startsWith("<?xml") || value.trim().startsWith("<"))
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
245
257
|
/**
|
|
246
258
|
* Resolves a runtime expression to its value in the context
|
|
247
259
|
* @public
|
|
@@ -470,6 +482,18 @@ class Expression {
|
|
|
470
482
|
throw new Error(`Context path '${normalised}' not found`);
|
|
471
483
|
}
|
|
472
484
|
|
|
485
|
+
// NEW: Check if contextData is XML
|
|
486
|
+
if (this.isXML(contextData)) {
|
|
487
|
+
const { XMLParser } = require("fast-xml-parser");
|
|
488
|
+
const parser = new XMLParser({
|
|
489
|
+
ignoreAttributes: false,
|
|
490
|
+
attributeNamePrefix: "@_",
|
|
491
|
+
});
|
|
492
|
+
const jsonData = parser.parse(contextData);
|
|
493
|
+
return evaluate(jsonData, pointer);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Regular JSON pointer evaluation
|
|
473
497
|
try {
|
|
474
498
|
return evaluate(contextData, pointer);
|
|
475
499
|
} catch (err) {
|