apcore-cli 0.9.0 → 0.9.1
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/CHANGELOG.md +18 -0
- package/dist/bin/apcore-cli.js +38 -0
- package/dist/bin/apcore-cli.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -850,6 +850,7 @@ declare class ApprovalDeniedError extends Error {
|
|
|
850
850
|
}
|
|
851
851
|
/** Thrown when schema validation fails. */
|
|
852
852
|
declare class SchemaValidationError extends Error {
|
|
853
|
+
readonly code = "SCHEMA_VALIDATION_ERROR";
|
|
853
854
|
constructor(message?: string);
|
|
854
855
|
}
|
|
855
856
|
/** Thrown when $ref resolution depth exceeds the configured maximum. */
|
package/dist/index.js
CHANGED
|
@@ -115,6 +115,7 @@ var init_errors = __esm({
|
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
117
|
SchemaValidationError = class extends Error {
|
|
118
|
+
code = "SCHEMA_VALIDATION_ERROR";
|
|
118
119
|
constructor(message = "Schema validation failed") {
|
|
119
120
|
super(message);
|
|
120
121
|
this.name = "SchemaValidationError";
|
|
@@ -3653,6 +3654,37 @@ try {
|
|
|
3653
3654
|
VERSION = pkg.version;
|
|
3654
3655
|
} catch {
|
|
3655
3656
|
}
|
|
3657
|
+
function validateInputSchema(schema, input) {
|
|
3658
|
+
const required = schema.required;
|
|
3659
|
+
if (required && Array.isArray(required)) {
|
|
3660
|
+
for (const field of required) {
|
|
3661
|
+
const val = input[field];
|
|
3662
|
+
if (val === null || val === void 0) {
|
|
3663
|
+
return `'${field}' is required`;
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
const properties = schema.properties;
|
|
3668
|
+
if (properties) {
|
|
3669
|
+
for (const [field, propSchema] of Object.entries(properties)) {
|
|
3670
|
+
const val = input[field];
|
|
3671
|
+
if (val === null || val === void 0) continue;
|
|
3672
|
+
const expectedType = propSchema.type;
|
|
3673
|
+
if (!expectedType) continue;
|
|
3674
|
+
const actualType = typeof val;
|
|
3675
|
+
if (expectedType === "string" && actualType !== "string") {
|
|
3676
|
+
return `'${field}' must be a string, got ${actualType}`;
|
|
3677
|
+
}
|
|
3678
|
+
if ((expectedType === "integer" || expectedType === "number") && actualType !== "number") {
|
|
3679
|
+
return `'${field}' must be a number, got ${actualType}`;
|
|
3680
|
+
}
|
|
3681
|
+
if (expectedType === "boolean" && actualType !== "boolean") {
|
|
3682
|
+
return `'${field}' must be a boolean, got ${actualType}`;
|
|
3683
|
+
}
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
return null;
|
|
3687
|
+
}
|
|
3656
3688
|
function emitErrorJson(e, exitCode) {
|
|
3657
3689
|
const err = e instanceof Error ? e : new Error(String(e));
|
|
3658
3690
|
const errRecord = err;
|
|
@@ -4165,6 +4197,12 @@ function buildModuleCommand(moduleDef, executor, helpTextMaxLength = 1e3, cmdNam
|
|
|
4165
4197
|
}
|
|
4166
4198
|
process.exit(preflight.valid ? 0 : firstFailedExitCode(preflight));
|
|
4167
4199
|
}
|
|
4200
|
+
if (resolvedSchema.properties) {
|
|
4201
|
+
const validationErr = validateInputSchema(resolvedSchema, merged);
|
|
4202
|
+
if (validationErr) {
|
|
4203
|
+
throw new SchemaValidationError(`Validation failed: ${validationErr}`);
|
|
4204
|
+
}
|
|
4205
|
+
}
|
|
4168
4206
|
if (approvalToken) {
|
|
4169
4207
|
merged._approval_token = approvalToken;
|
|
4170
4208
|
}
|