@govtechsg/open-attestation
Version:
19 lines (18 loc) • 799 B
JavaScript
import { getLogger } from "../logger";
import { SchemaId } from "../@types/document";
// don't change this otherwise there is a cycle
import { getData } from "../utils/utils";
var logger = getLogger("validate");
export var validateSchema = function (document, validator, kind) {
var _a;
if (!validator) {
throw new Error("No schema validator provided");
}
var valid = validator(document.version === SchemaId.v3 || kind === "raw" ? document : getData(document));
if (!valid) {
logger.debug("There are errors in the document: ".concat(JSON.stringify(validator.errors)));
return (_a = validator.errors) !== null && _a !== void 0 ? _a : [];
}
logger.debug("Document is a valid open attestation document v".concat(document.version));
return [];
};