@amplience/dc-cli
Version:
Dynamic Content CLI Tool
31 lines (30 loc) • 1.26 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createContentTypeSchema = void 0;
const dc_management_sdk_js_1 = require("dc-management-sdk-js");
const resolve_schema_id_1 = __importDefault(require("../../common/json-schema/resolve-schema-id"));
const createContentTypeSchema = async (schemaBody, validationLevel, hub) => {
let schemaJson;
try {
schemaJson = JSON.parse(schemaBody);
}
catch (err) {
throw new Error('Unable to parse schema body');
}
const schemaId = (0, resolve_schema_id_1.default)(schemaJson);
if (schemaId === undefined) {
throw new Error('Missing id from schema');
}
else if (!schemaId) {
throw new Error('The supplied schema id is invalid');
}
const contentTypeSchema = new dc_management_sdk_js_1.ContentTypeSchema();
contentTypeSchema.body = schemaBody;
contentTypeSchema.schemaId = schemaId;
contentTypeSchema.validationLevel = validationLevel;
return hub.related.contentTypeSchema.create(contentTypeSchema);
};
exports.createContentTypeSchema = createContentTypeSchema;