📦 deps(thirdparty): update snapshots
This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
|
||||
const versions = require("../versions");
|
||||
const { canonicalJson, sha256 } = require("../canonical-json");
|
||||
const { sanitizeValidationDetails } = require("../schema-validator");
|
||||
|
||||
const DIGEST_PATTERN = /^sha256-[a-f0-9]{64}$/;
|
||||
const ID_PATTERN = /^[a-z0-9][a-z0-9._-]*(?:\/[a-z0-9][a-z0-9._-]*)*$/;
|
||||
const PACKAGE_PATTERN = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
|
||||
const SUPPORTED_HOSTS = new Set(["codex", "claude"]);
|
||||
const SUPPORTED_SCOPES = new Set(["project", "user"]);
|
||||
const SUPPORTED_RISKS = new Set(["none", "safe", "unknown", "critical", "offensive"]);
|
||||
|
||||
function isPlainObject(value) {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
||||
@@ -16,25 +16,33 @@ function isPlainObject(value) {
|
||||
return prototype === Object.prototype || prototype === null;
|
||||
}
|
||||
|
||||
function issue(path, code, details = {}) {
|
||||
return { path, code, ...details };
|
||||
function issue(field, code, keyword, limit) {
|
||||
return { field, code, keyword, ...(limit === undefined ? {} : { limit }) };
|
||||
}
|
||||
|
||||
function rejectUnknownKeys(value, allowed, path, issues) {
|
||||
if (!isPlainObject(value)) return;
|
||||
for (const key of Object.keys(value).sort()) {
|
||||
if (!allowed.has(key)) issues.push(issue(`${path}.${key}`, "AAS_STACK_FIELD_UNKNOWN"));
|
||||
if (!allowed.has(key)) issues.push(issue(path, "AAS_STACK_FIELD_UNKNOWN", "additionalProperties", false));
|
||||
}
|
||||
}
|
||||
|
||||
function validateString(value, path, issues, options = {}) {
|
||||
const { minimum = 1, maximum = 256, pattern } = options;
|
||||
if (typeof value !== "string" || value.length < minimum || value.length > maximum) {
|
||||
issues.push(issue(path, "AAS_STACK_STRING_INVALID"));
|
||||
if (typeof value !== "string") {
|
||||
issues.push(issue(path, "AAS_STACK_STRING_INVALID", "type", "string"));
|
||||
return false;
|
||||
}
|
||||
if (value.length < minimum) {
|
||||
issues.push(issue(path, "AAS_STACK_STRING_INVALID", "minLength", minimum));
|
||||
return false;
|
||||
}
|
||||
if (value.length > maximum) {
|
||||
issues.push(issue(path, "AAS_STACK_STRING_INVALID", "maxLength", maximum));
|
||||
return false;
|
||||
}
|
||||
if (pattern && !pattern.test(value)) {
|
||||
issues.push(issue(path, "AAS_STACK_STRING_FORMAT_INVALID"));
|
||||
issues.push(issue(path, "AAS_STACK_STRING_FORMAT_INVALID", "pattern"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -42,47 +50,55 @@ function validateString(value, path, issues, options = {}) {
|
||||
|
||||
function validateUniqueStringArray(value, path, issues, options = {}) {
|
||||
const { minimum = 0, maximum = 64, pattern, allowed } = options;
|
||||
if (!Array.isArray(value) || value.length < minimum || value.length > maximum) {
|
||||
issues.push(issue(path, "AAS_STACK_ARRAY_INVALID"));
|
||||
if (!Array.isArray(value)) {
|
||||
issues.push(issue(path, "AAS_STACK_ARRAY_INVALID", "type", "array"));
|
||||
return;
|
||||
}
|
||||
if (value.length < minimum) {
|
||||
issues.push(issue(path, "AAS_STACK_ARRAY_INVALID", "minItems", minimum));
|
||||
return;
|
||||
}
|
||||
if (value.length > maximum) {
|
||||
issues.push(issue(path, "AAS_STACK_ARRAY_INVALID", "maxItems", maximum));
|
||||
return;
|
||||
}
|
||||
const seen = new Set();
|
||||
value.forEach((entry, index) => {
|
||||
if (!validateString(entry, `${path}[${index}]`, issues, { maximum: 128, pattern })) return;
|
||||
if (allowed && !allowed.has(entry)) issues.push(issue(`${path}[${index}]`, "AAS_STACK_VALUE_UNSUPPORTED"));
|
||||
if (seen.has(entry)) issues.push(issue(`${path}[${index}]`, "AAS_STACK_VALUE_DUPLICATE"));
|
||||
if (allowed && !allowed.has(entry)) issues.push(issue(`${path}[${index}]`, "AAS_STACK_VALUE_UNSUPPORTED", "enum"));
|
||||
if (seen.has(entry)) issues.push(issue(`${path}[${index}]`, "AAS_STACK_VALUE_DUPLICATE", "uniqueItems"));
|
||||
seen.add(entry);
|
||||
});
|
||||
}
|
||||
|
||||
function invalidResult(issues) {
|
||||
return {
|
||||
schemaVersion: 1,
|
||||
schemaVersion: 2,
|
||||
ok: false,
|
||||
status: "invalid",
|
||||
...versions,
|
||||
code: "AAS_STACK_MANIFEST_INVALID",
|
||||
category: "invalidInput",
|
||||
details: { issues },
|
||||
details: sanitizeValidationDetails({ issues }),
|
||||
};
|
||||
}
|
||||
|
||||
function validateManifest(manifest) {
|
||||
const issues = [];
|
||||
if (!isPlainObject(manifest)) return invalidResult([issue("$", "AAS_STACK_OBJECT_REQUIRED")]);
|
||||
if (!isPlainObject(manifest)) return invalidResult([issue("manifest", "AAS_STACK_OBJECT_REQUIRED", "type", "object")]);
|
||||
|
||||
rejectUnknownKeys(
|
||||
manifest,
|
||||
new Set(["schemaVersion", "name", "catalog", "targets", "intent", "policy", "skills"]),
|
||||
new Set(["schemaVersion", "name", "catalog", "targets", "profile", "skills"]),
|
||||
"$",
|
||||
issues,
|
||||
);
|
||||
|
||||
if (manifest.schemaVersion !== 1) issues.push(issue("$.schemaVersion", "AAS_STACK_SCHEMA_VERSION_UNSUPPORTED"));
|
||||
if (manifest.schemaVersion !== 2) issues.push(issue("schemaVersion", "AAS_STACK_SCHEMA_VERSION_UNSUPPORTED", "const", 2));
|
||||
validateString(manifest.name, "$.name", issues, { maximum: 128, pattern: /^[A-Za-z0-9][A-Za-z0-9._ -]*$/ });
|
||||
|
||||
if (!isPlainObject(manifest.catalog)) {
|
||||
issues.push(issue("$.catalog", "AAS_STACK_OBJECT_REQUIRED"));
|
||||
issues.push(issue("catalog", "AAS_STACK_OBJECT_REQUIRED", "type", "object"));
|
||||
} else {
|
||||
rejectUnknownKeys(manifest.catalog, new Set(["package", "version", "integrity"]), "$.catalog", issues);
|
||||
validateString(manifest.catalog.package, "$.catalog.package", issues, { maximum: 214, pattern: PACKAGE_PATTERN });
|
||||
@@ -91,67 +107,56 @@ function validateManifest(manifest) {
|
||||
}
|
||||
|
||||
if (!Array.isArray(manifest.targets) || manifest.targets.length < 1 || manifest.targets.length > 8) {
|
||||
issues.push(issue("$.targets", "AAS_STACK_TARGETS_INVALID"));
|
||||
const keyword = !Array.isArray(manifest.targets) ? "type" : manifest.targets.length < 1 ? "minItems" : "maxItems";
|
||||
const limit = keyword === "type" ? "array" : keyword === "minItems" ? 1 : 8;
|
||||
issues.push(issue("targets", "AAS_STACK_TARGETS_INVALID", keyword, limit));
|
||||
} else {
|
||||
const seenTargets = new Set();
|
||||
manifest.targets.forEach((target, index) => {
|
||||
const path = `$.targets[${index}]`;
|
||||
if (!isPlainObject(target)) {
|
||||
issues.push(issue(path, "AAS_STACK_OBJECT_REQUIRED"));
|
||||
issues.push(issue(path, "AAS_STACK_OBJECT_REQUIRED", "type", "object"));
|
||||
return;
|
||||
}
|
||||
rejectUnknownKeys(target, new Set(["host", "scope"]), path, issues);
|
||||
if (!SUPPORTED_HOSTS.has(target.host)) issues.push(issue(`${path}.host`, "AAS_STACK_TARGET_HOST_UNSUPPORTED"));
|
||||
if (!SUPPORTED_SCOPES.has(target.scope)) issues.push(issue(`${path}.scope`, "AAS_STACK_TARGET_SCOPE_UNSUPPORTED"));
|
||||
if (!SUPPORTED_HOSTS.has(target.host)) issues.push(issue(`${path}.host`, "AAS_STACK_TARGET_HOST_UNSUPPORTED", "enum"));
|
||||
if (!SUPPORTED_SCOPES.has(target.scope)) issues.push(issue(`${path}.scope`, "AAS_STACK_TARGET_SCOPE_UNSUPPORTED", "enum"));
|
||||
const key = `${target.host}:${target.scope}`;
|
||||
if (seenTargets.has(key)) issues.push(issue(path, "AAS_STACK_TARGET_DUPLICATE"));
|
||||
if (seenTargets.has(key)) issues.push(issue(path, "AAS_STACK_TARGET_DUPLICATE", "uniqueItems"));
|
||||
seenTargets.add(key);
|
||||
});
|
||||
}
|
||||
|
||||
if (!isPlainObject(manifest.intent)) {
|
||||
issues.push(issue("$.intent", "AAS_STACK_OBJECT_REQUIRED"));
|
||||
if (!isPlainObject(manifest.profile)) {
|
||||
issues.push(issue("profile", "AAS_STACK_OBJECT_REQUIRED", "type", "object"));
|
||||
} else {
|
||||
rejectUnknownKeys(manifest.intent, new Set(["goals"]), "$.intent", issues);
|
||||
validateUniqueStringArray(manifest.intent.goals, "$.intent.goals", issues, {
|
||||
rejectUnknownKeys(manifest.profile, new Set(["goals", "projectType", "languages", "frameworks", "constraints"]), "$.profile", issues);
|
||||
validateUniqueStringArray(manifest.profile.goals, "$.profile.goals", issues, {
|
||||
minimum: 1,
|
||||
maximum: 32,
|
||||
pattern: ID_PATTERN,
|
||||
});
|
||||
}
|
||||
|
||||
if (!isPlainObject(manifest.policy)) {
|
||||
issues.push(issue("$.policy", "AAS_STACK_OBJECT_REQUIRED"));
|
||||
} else {
|
||||
rejectUnknownKeys(
|
||||
manifest.policy,
|
||||
new Set(["allowedRisk", "requireKnownSource", "allowManualSetup"]),
|
||||
"$.policy",
|
||||
issues,
|
||||
);
|
||||
validateUniqueStringArray(manifest.policy.allowedRisk, "$.policy.allowedRisk", issues, {
|
||||
minimum: 1,
|
||||
maximum: 5,
|
||||
allowed: SUPPORTED_RISKS,
|
||||
});
|
||||
for (const key of ["requireKnownSource", "allowManualSetup"]) {
|
||||
if (typeof manifest.policy[key] !== "boolean") issues.push(issue(`$.policy.${key}`, "AAS_STACK_BOOLEAN_REQUIRED"));
|
||||
if (manifest.profile.projectType !== undefined) {
|
||||
validateString(manifest.profile.projectType, "$.profile.projectType", issues, { maximum: 256 });
|
||||
}
|
||||
for (const key of ["languages", "frameworks", "constraints"]) {
|
||||
validateUniqueStringArray(manifest.profile[key], `$.profile.${key}`, issues, { maximum: 32 });
|
||||
}
|
||||
}
|
||||
|
||||
if (!Array.isArray(manifest.skills) || manifest.skills.length > 128) {
|
||||
issues.push(issue("$.skills", "AAS_STACK_SKILLS_INVALID"));
|
||||
const keyword = !Array.isArray(manifest.skills) ? "type" : "maxItems";
|
||||
issues.push(issue("skills", "AAS_STACK_SKILLS_INVALID", keyword, keyword === "type" ? "array" : 128));
|
||||
} else {
|
||||
const seenSkills = new Set();
|
||||
manifest.skills.forEach((skill, index) => {
|
||||
const path = `$.skills[${index}]`;
|
||||
if (!isPlainObject(skill)) {
|
||||
issues.push(issue(path, "AAS_STACK_OBJECT_REQUIRED"));
|
||||
issues.push(issue(path, "AAS_STACK_OBJECT_REQUIRED", "type", "object"));
|
||||
return;
|
||||
}
|
||||
rejectUnknownKeys(skill, new Set(["id"]), path, issues);
|
||||
if (validateString(skill.id, `${path}.id`, issues, { maximum: 256, pattern: ID_PATTERN })) {
|
||||
if (seenSkills.has(skill.id)) issues.push(issue(`${path}.id`, "AAS_STACK_SKILL_DUPLICATE"));
|
||||
if (seenSkills.has(skill.id)) issues.push(issue(`${path}.id`, "AAS_STACK_SKILL_DUPLICATE", "uniqueItems"));
|
||||
seenSkills.add(skill.id);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user