@rogatio/cli 6.20.3 → 6.20.5
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/dist/editor/index.js +16 -16
- package/dist/node/index.js +21 -6
- package/package.json +1 -1
package/dist/editor/index.js
CHANGED
|
@@ -263,6 +263,14 @@ var HTTP_METHODS = Object.freeze([
|
|
|
263
263
|
"CONNECT",
|
|
264
264
|
"TRACE"
|
|
265
265
|
]);
|
|
266
|
+
function compileReplacementRegex(value) {
|
|
267
|
+
if (typeof value !== "string" || value.length === 0) return null;
|
|
268
|
+
try {
|
|
269
|
+
return new RegExp(value, "u");
|
|
270
|
+
} catch {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
266
274
|
function hasLoneSurrogate(value) {
|
|
267
275
|
for (let i = 0; i < value.length; i += 1) {
|
|
268
276
|
const code = value.charCodeAt(i);
|
|
@@ -1519,17 +1527,13 @@ function createRequestBodyRuleType() {
|
|
|
1519
1527
|
path: `${rulePath}/requestBody/pattern`,
|
|
1520
1528
|
message: "Regex pattern must not contain lone UTF-16 surrogates."
|
|
1521
1529
|
});
|
|
1522
|
-
} else {
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
path: `${rulePath}/requestBody/pattern`,
|
|
1530
|
-
message: "Regex pattern must be a valid regular expression."
|
|
1531
|
-
});
|
|
1532
|
-
}
|
|
1530
|
+
} else if (compileReplacementRegex(action.pattern) === null) {
|
|
1531
|
+
diagnostics.push({
|
|
1532
|
+
code: "editor.request-body-pattern",
|
|
1533
|
+
severity: "error",
|
|
1534
|
+
path: `${rulePath}/requestBody/pattern`,
|
|
1535
|
+
message: "Regex pattern must be a valid regular expression."
|
|
1536
|
+
});
|
|
1533
1537
|
}
|
|
1534
1538
|
if (typeof action.replacement !== "string" || action.replacement.length > LIMITS.maxRequestBodyReplacementLength) {
|
|
1535
1539
|
diagnostics.push({
|
|
@@ -1677,11 +1681,7 @@ function validateRegexReplacements(replacements, rulePath) {
|
|
|
1677
1681
|
replacements.forEach((entry, index) => {
|
|
1678
1682
|
const patternPath = `${rulePath}/responseBody/replacements/${index}/pattern`;
|
|
1679
1683
|
const replacementPath = `${rulePath}/responseBody/replacements/${index}/replacement`;
|
|
1680
|
-
|
|
1681
|
-
if (typeof entry?.pattern !== "string" || entry.pattern.length === 0 || entry.pattern.length > LIMITS.maxResponseBodyPatternLength)
|
|
1682
|
-
throw new Error();
|
|
1683
|
-
new RegExp(entry.pattern, "u");
|
|
1684
|
-
} catch {
|
|
1684
|
+
if (typeof entry?.pattern !== "string" || entry.pattern.length === 0 || entry.pattern.length > LIMITS.maxResponseBodyPatternLength || compileReplacementRegex(entry.pattern) === null) {
|
|
1685
1685
|
diagnostics.push({
|
|
1686
1686
|
code: "editor.response-body-pattern",
|
|
1687
1687
|
severity: "error",
|
package/dist/node/index.js
CHANGED
|
@@ -628,6 +628,14 @@ function compileUrlRegex(value) {
|
|
|
628
628
|
return null;
|
|
629
629
|
}
|
|
630
630
|
}
|
|
631
|
+
function compileReplacementRegex(value) {
|
|
632
|
+
if (typeof value !== "string" || value.length === 0) return null;
|
|
633
|
+
try {
|
|
634
|
+
return new RegExp(value, "u");
|
|
635
|
+
} catch {
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
631
639
|
var label = {
|
|
632
640
|
type: "string",
|
|
633
641
|
minLength: 1,
|
|
@@ -959,7 +967,7 @@ var projectSchemaDefinition = {
|
|
|
959
967
|
type: "string",
|
|
960
968
|
minLength: 1,
|
|
961
969
|
maxLength: LIMITS.maxResponseBodyPatternLength,
|
|
962
|
-
format: "rogatio-
|
|
970
|
+
format: "rogatio-replacement-regex"
|
|
963
971
|
},
|
|
964
972
|
replacement: {
|
|
965
973
|
type: "string",
|
|
@@ -1035,7 +1043,7 @@ var projectSchemaDefinition = {
|
|
|
1035
1043
|
type: "string",
|
|
1036
1044
|
minLength: 1,
|
|
1037
1045
|
maxLength: LIMITS.maxRequestBodyPatternLength,
|
|
1038
|
-
format: "rogatio-
|
|
1046
|
+
format: "rogatio-replacement-regex"
|
|
1039
1047
|
},
|
|
1040
1048
|
replacement: {
|
|
1041
1049
|
type: "string",
|
|
@@ -1200,6 +1208,10 @@ ajv.addFormat("rogatio-url-regex", {
|
|
|
1200
1208
|
type: "string",
|
|
1201
1209
|
validate: (value) => compileUrlRegex(value) !== null
|
|
1202
1210
|
});
|
|
1211
|
+
ajv.addFormat("rogatio-replacement-regex", {
|
|
1212
|
+
type: "string",
|
|
1213
|
+
validate: (value) => compileReplacementRegex(value) !== null
|
|
1214
|
+
});
|
|
1203
1215
|
function ajvIssues(errors) {
|
|
1204
1216
|
return (errors ?? []).map((error) => ({
|
|
1205
1217
|
// Ajv reports a `required` violation against the object that lacks the
|
|
@@ -1525,7 +1537,7 @@ function semanticIssues(project) {
|
|
|
1525
1537
|
} else {
|
|
1526
1538
|
for (let index = 0; index < action2.replacements.length; index += 1) {
|
|
1527
1539
|
const replacement = action2.replacements[index];
|
|
1528
|
-
if (
|
|
1540
|
+
if (compileReplacementRegex(replacement.pattern) === null) {
|
|
1529
1541
|
issues.push({
|
|
1530
1542
|
instancePath: `${actionPath}/replacements/${index}/pattern`,
|
|
1531
1543
|
keyword: "response-body-pattern",
|
|
@@ -1611,7 +1623,7 @@ function semanticIssues(project) {
|
|
|
1611
1623
|
message: `Regex pattern exceeds the maximum length of ${LIMITS.maxRequestBodyPatternLength} characters.`,
|
|
1612
1624
|
params: { limit: LIMITS.maxRequestBodyPatternLength }
|
|
1613
1625
|
});
|
|
1614
|
-
} else if (
|
|
1626
|
+
} else if (compileReplacementRegex(action2.pattern) === null) {
|
|
1615
1627
|
issues.push({
|
|
1616
1628
|
instancePath: `${actionPath}/pattern`,
|
|
1617
1629
|
keyword: "request-body-pattern",
|
|
@@ -23887,13 +23899,16 @@ function generatePacScript(routes, endpoint, options) {
|
|
|
23887
23899
|
""
|
|
23888
23900
|
].join("\n");
|
|
23889
23901
|
}
|
|
23902
|
+
function schemaDiagnosticCode(keyword) {
|
|
23903
|
+
return keyword.startsWith("schema.") ? keyword : `schema.${keyword}`;
|
|
23904
|
+
}
|
|
23890
23905
|
function diagnoseProjectData(projectData) {
|
|
23891
23906
|
const diagnostics = [];
|
|
23892
23907
|
const schemaResult = validateProjectDetailed(projectData);
|
|
23893
23908
|
if (!schemaResult.valid) {
|
|
23894
23909
|
for (const error of schemaResult.errors) {
|
|
23895
23910
|
diagnostics.push({
|
|
23896
|
-
code:
|
|
23911
|
+
code: schemaDiagnosticCode(error.keyword),
|
|
23897
23912
|
severity: "error",
|
|
23898
23913
|
path: error.instancePath || "/",
|
|
23899
23914
|
message: error.message,
|
|
@@ -33752,7 +33767,7 @@ async function runtimeHostCommand(args, options = {}) {
|
|
|
33752
33767
|
if (!schemaResult.valid) {
|
|
33753
33768
|
for (const issue of schemaResult.errors) {
|
|
33754
33769
|
console.error(
|
|
33755
|
-
`${issue.instancePath || "/"}/: ${issue.message} (
|
|
33770
|
+
`${issue.instancePath || "/"}/: ${issue.message} (${schemaDiagnosticCode(issue.keyword)})`
|
|
33756
33771
|
);
|
|
33757
33772
|
}
|
|
33758
33773
|
return 1;
|
package/package.json
CHANGED