UNPKG

mtn-open-api

Version:

A Node.js package for interacting with MTN Open API

1,164 lines (1,160 loc) 312 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) { if (typeof require !== "undefined") return require.apply(this, arguments); throw Error('Dynamic require of "' + x + '" is not supported'); }); var __commonJS = (cb, mod) => function __require2() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); // node_modules/jsonschema/lib/helpers.js var require_helpers = __commonJS({ "node_modules/jsonschema/lib/helpers.js"(exports, module) { "use strict"; var uri = __require("url"); var ValidationError = exports.ValidationError = function ValidationError2(message, instance, schema, path, name, argument) { if (Array.isArray(path)) { this.path = path; this.property = path.reduce(function(sum, item) { return sum + makeSuffix(item); }, "instance"); } else if (path !== void 0) { this.property = path; } if (message) { this.message = message; } if (schema) { var id = schema.$id || schema.id; this.schema = id || schema; } if (instance !== void 0) { this.instance = instance; } this.name = name; this.argument = argument; this.stack = this.toString(); }; ValidationError.prototype.toString = function toString() { return this.property + " " + this.message; }; var ValidatorResult = exports.ValidatorResult = function ValidatorResult2(instance, schema, options, ctx) { this.instance = instance; this.schema = schema; this.options = options; this.path = ctx.path; this.propertyPath = ctx.propertyPath; this.errors = []; this.throwError = options && options.throwError; this.throwFirst = options && options.throwFirst; this.throwAll = options && options.throwAll; this.disableFormat = options && options.disableFormat === true; }; ValidatorResult.prototype.addError = function addError(detail) { var err; if (typeof detail == "string") { err = new ValidationError(detail, this.instance, this.schema, this.path); } else { if (!detail) throw new Error("Missing error detail"); if (!detail.message) throw new Error("Missing error message"); if (!detail.name) throw new Error("Missing validator type"); err = new ValidationError(detail.message, this.instance, this.schema, this.path, detail.name, detail.argument); } this.errors.push(err); if (this.throwFirst) { throw new ValidatorResultError(this); } else if (this.throwError) { throw err; } return err; }; ValidatorResult.prototype.importErrors = function importErrors(res) { if (typeof res == "string" || res && res.validatorType) { this.addError(res); } else if (res && res.errors) { this.errors = this.errors.concat(res.errors); } }; function stringizer(v, i) { return i + ": " + v.toString() + "\n"; } ValidatorResult.prototype.toString = function toString(res) { return this.errors.map(stringizer).join(""); }; Object.defineProperty(ValidatorResult.prototype, "valid", { get: function() { return !this.errors.length; } }); module.exports.ValidatorResultError = ValidatorResultError; function ValidatorResultError(result) { if (Error.captureStackTrace) { Error.captureStackTrace(this, ValidatorResultError); } this.instance = result.instance; this.schema = result.schema; this.options = result.options; this.errors = result.errors; } ValidatorResultError.prototype = new Error(); ValidatorResultError.prototype.constructor = ValidatorResultError; ValidatorResultError.prototype.name = "Validation Error"; var SchemaError = exports.SchemaError = function SchemaError2(msg, schema) { this.message = msg; this.schema = schema; Error.call(this, msg); Error.captureStackTrace(this, SchemaError2); }; SchemaError.prototype = Object.create( Error.prototype, { constructor: { value: SchemaError, enumerable: false }, name: { value: "SchemaError", enumerable: false } } ); var SchemaContext = exports.SchemaContext = function SchemaContext2(schema, options, path, base, schemas) { this.schema = schema; this.options = options; if (Array.isArray(path)) { this.path = path; this.propertyPath = path.reduce(function(sum, item) { return sum + makeSuffix(item); }, "instance"); } else { this.propertyPath = path; } this.base = base; this.schemas = schemas; }; SchemaContext.prototype.resolve = function resolve(target) { return uri.resolve(this.base, target); }; SchemaContext.prototype.makeChild = function makeChild(schema, propertyName) { var path = propertyName === void 0 ? this.path : this.path.concat([propertyName]); var id = schema.$id || schema.id; var base = uri.resolve(this.base, id || ""); var ctx = new SchemaContext(schema, this.options, path, base, Object.create(this.schemas)); if (id && !ctx.schemas[base]) { ctx.schemas[base] = schema; } return ctx; }; var FORMAT_REGEXPS = exports.FORMAT_REGEXPS = { // 7.3.1. Dates, Times, and Duration "date-time": /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])[tT ](2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])(\.\d+)?([zZ]|[+-]([0-5][0-9]):(60|[0-5][0-9]))$/, "date": /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])$/, "time": /^(2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])$/, "duration": /P(T\d+(H(\d+M(\d+S)?)?|M(\d+S)?|S)|\d+(D|M(\d+D)?|Y(\d+M(\d+D)?)?)(T\d+(H(\d+M(\d+S)?)?|M(\d+S)?|S))?|\d+W)/i, // 7.3.2. Email Addresses // TODO: fix the email production "email": /^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/, "idn-email": /^("(?:[!#-\[\]-\u{10FFFF}]|\\[\t -\u{10FFFF}])*"|[!#-'*+\-/-9=?A-Z\^-\u{10FFFF}](?:\.?[!#-'*+\-/-9=?A-Z\^-\u{10FFFF}])*)@([!#-'*+\-/-9=?A-Z\^-\u{10FFFF}](?:\.?[!#-'*+\-/-9=?A-Z\^-\u{10FFFF}])*|\[[!-Z\^-\u{10FFFF}]*\])$/u, // 7.3.3. Hostnames // 7.3.4. IP Addresses "ip-address": /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/, // FIXME whitespace is invalid "ipv6": /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9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0-9a-f]{2}|[0-9_a-z]))*(:[1-9]\d{0,3}|\*)?(,(%[0-9a-f]{2}|[0-9_a-z])(\.?(%[0-9a-f]{2}|[0-9_a-z]))*(:[1-9]\d{0,3}|\*)?)*\})*/iu, // 7.3.7. JSON Pointers "json-pointer": /^(\/([\x00-\x2e0-@\[-}\x7f]|~[01])*)*$/iu, "relative-json-pointer": /^\d+(#|(\/([\x00-\x2e0-@\[-}\x7f]|~[01])*)*)$/iu, // hostname regex from: http://stackoverflow.com/a/1420225/5628 "hostname": /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/, "host-name": /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/, "utc-millisec": function(input) { return typeof input === "string" && parseFloat(input) === parseInt(input, 10) && !isNaN(input); }, // 7.3.8. regex "regex": function(input) { var result = true; try { new RegExp(input); } catch (e) { result = false; } return result; }, // Other definitions // "style" was removed from JSON Schema in draft-4 and is deprecated "style": /[\r\n\t ]*[^\r\n\t ][^:]*:[\r\n\t ]*[^\r\n\t ;]*[\r\n\t ]*;?/, // "color" was removed from JSON Schema in draft-4 and is deprecated "color": /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/, "phone": /^\+(?:[0-9] ?){6,14}[0-9]$/, "alpha": /^[a-zA-Z]+$/, "alphanumeric": /^[a-zA-Z0-9]+$/ }; FORMAT_REGEXPS.regexp = FORMAT_REGEXPS.regex; FORMAT_REGEXPS.pattern = FORMAT_REGEXPS.regex; FORMAT_REGEXPS.ipv4 = FORMAT_REGEXPS["ip-address"]; exports.isFormat = function isFormat(input, format, validator) { if (typeof input === "string" && FORMAT_REGEXPS[format] !== void 0) { if (FORMAT_REGEXPS[format] instanceof RegExp) { return FORMAT_REGEXPS[format].test(input); } if (typeof FORMAT_REGEXPS[format] === "function") { return FORMAT_REGEXPS[format](input); } } else if (validator && validator.customFormats && typeof validator.customFormats[format] === "function") { return validator.customFormats[format](input); } return true; }; var makeSuffix = exports.makeSuffix = function makeSuffix2(key) { key = key.toString(); if (!key.match(/[.\s\[\]]/) && !key.match(/^[\d]/)) { return "." + key; } if (key.match(/^\d+$/)) { return "[" + key + "]"; } return "[" + JSON.stringify(key) + "]"; }; exports.deepCompareStrict = function deepCompareStrict(a, b) { if (typeof a !== typeof b) { return false; } if (Array.isArray(a)) { if (!Array.isArray(b)) { return false; } if (a.length !== b.length) { return false; } return a.every(function(v, i) { return deepCompareStrict(a[i], b[i]); }); } if (typeof a === "object") { if (!a || !b) { return a === b; } var aKeys = Object.keys(a); var bKeys = Object.keys(b); if (aKeys.length !== bKeys.length) { return false; } return aKeys.every(function(v) { return deepCompareStrict(a[v], b[v]); }); } return a === b; }; function deepMerger(target, dst, e, i) { if (typeof e === "object") { dst[i] = deepMerge(target[i], e); } else { if (target.indexOf(e) === -1) { dst.push(e); } } } function copyist(src, dst, key) { dst[key] = src[key]; } function copyistWithDeepMerge(target, src, dst, key) { if (typeof src[key] !== "object" || !src[key]) { dst[key] = src[key]; } else { if (!target[key]) { dst[key] = src[key]; } else { dst[key] = deepMerge(target[key], src[key]); } } } function deepMerge(target, src) { var array = Array.isArray(src); var dst = array && [] || {}; if (array) { target = target || []; dst = dst.concat(target); src.forEach(deepMerger.bind(null, target, dst)); } else { if (target && typeof target === "object") { Object.keys(target).forEach(copyist.bind(null, target, dst)); } Object.keys(src).forEach(copyistWithDeepMerge.bind(null, target, src, dst)); } return dst; } module.exports.deepMerge = deepMerge; exports.objectGetPath = function objectGetPath(o, s) { var parts = s.split("/").slice(1); var k; while (typeof (k = parts.shift()) == "string") { var n = decodeURIComponent(k.replace(/~0/, "~").replace(/~1/g, "/")); if (!(n in o)) return; o = o[n]; } return o; }; function pathEncoder(v) { return "/" + encodeURIComponent(v).replace(/~/g, "%7E"); } exports.encodePath = function encodePointer(a) { return a.map(pathEncoder).join(""); }; exports.getDecimalPlaces = function getDecimalPlaces(number) { var decimalPlaces = 0; if (isNaN(number)) return decimalPlaces; if (typeof number !== "number") { number = Number(number); } var parts = number.toString().split("e"); if (parts.length === 2) { if (parts[1][0] !== "-") { return decimalPlaces; } else { decimalPlaces = Number(parts[1].slice(1)); } } var decimalParts = parts[0].split("."); if (decimalParts.length === 2) { decimalPlaces += decimalParts[1].length; } return decimalPlaces; }; exports.isSchema = function isSchema(val) { return typeof val === "object" && val || typeof val === "boolean"; }; } }); // node_modules/jsonschema/lib/attribute.js var require_attribute = __commonJS({ "node_modules/jsonschema/lib/attribute.js"(exports, module) { "use strict"; var helpers = require_helpers(); var ValidatorResult = helpers.ValidatorResult; var SchemaError = helpers.SchemaError; var attribute = {}; attribute.ignoreProperties = { // informative properties "id": true, "default": true, "description": true, "title": true, // arguments to other properties "additionalItems": true, "then": true, "else": true, // special-handled properties "$schema": true, "$ref": true, "extends": true }; var validators = attribute.validators = {}; validators.type = function validateType(instance, schema, options, ctx) { if (instance === void 0) { return null; } var result = new ValidatorResult(instance, schema, options, ctx); var types = Array.isArray(schema.type) ? schema.type : [schema.type]; if (!types.some(this.testType.bind(this, instance, schema, options, ctx))) { var list = types.map(function(v) { if (!v) return; var id = v.$id || v.id; return id ? "<" + id + ">" : v + ""; }); result.addError({ name: "type", argument: list, message: "is not of a type(s) " + list }); } return result; }; function testSchemaNoThrow(instance, options, ctx, callback, schema) { var throwError = options.throwError; var throwAll = options.throwAll; options.throwError = false; options.throwAll = false; var res = this.validateSchema(instance, schema, options, ctx); options.throwError = throwError; options.throwAll = throwAll; if (!res.valid && callback instanceof Function) { callback(res); } return res.valid; } validators.anyOf = function validateAnyOf(instance, schema, options, ctx) { if (instance === void 0) { return null; } var result = new ValidatorResult(instance, schema, options, ctx); var inner = new ValidatorResult(instance, schema, options, ctx); if (!Array.isArray(schema.anyOf)) { throw new SchemaError("anyOf must be an array"); } if (!schema.anyOf.some( testSchemaNoThrow.bind( this, instance, options, ctx, function(res) { inner.importErrors(res); } ) )) { var list = schema.anyOf.map(function(v, i) { var id = v.$id || v.id; if (id) return "<" + id + ">"; return v.title && JSON.stringify(v.title) || v["$ref"] && "<" + v["$ref"] + ">" || "[subschema " + i + "]"; }); if (options.nestedErrors) { result.importErrors(inner); } result.addError({ name: "anyOf", argument: list, message: "is not any of " + list.join(",") }); } return result; }; validators.allOf = function validateAllOf(instance, schema, options, ctx) { if (instance === void 0) { return null; } if (!Array.isArray(schema.allOf)) { throw new SchemaError("allOf must be an array"); } var result = new ValidatorResult(instance, schema, options, ctx); var self = this; schema.allOf.forEach(function(v, i) { var valid = self.validateSchema(instance, v, options, ctx); if (!valid.valid) { var id = v.$id || v.id; var msg = id || v.title && JSON.stringify(v.title) || v["$ref"] && "<" + v["$ref"] + ">" || "[subschema " + i + "]"; result.addError({ name: "allOf", argument: { id: msg, length: valid.errors.length, valid }, message: "does not match allOf schema " + msg + " with " + valid.errors.length + " error[s]:" }); result.importErrors(valid); } }); return result; }; validators.oneOf = function validateOneOf(instance, schema, options, ctx) { if (instance === void 0) { return null; } if (!Array.isArray(schema.oneOf)) { throw new SchemaError("oneOf must be an array"); } var result = new ValidatorResult(instance, schema, options, ctx); var inner = new ValidatorResult(instance, schema, options, ctx); var count = schema.oneOf.filter( testSchemaNoThrow.bind( this, instance, options, ctx, function(res) { inner.importErrors(res); } ) ).length; var list = schema.oneOf.map(function(v, i) { var id = v.$id || v.id; return id || v.title && JSON.stringify(v.title) || v["$ref"] && "<" + v["$ref"] + ">" || "[subschema " + i + "]"; }); if (count !== 1) { if (options.nestedErrors) { result.importErrors(inner); } result.addError({ name: "oneOf", argument: list, message: "is not exactly one from " + list.join(",") }); } return result; }; validators.if = function validateIf(instance, schema, options, ctx) { if (instance === void 0) return null; if (!helpers.isSchema(schema.if)) throw new Error('Expected "if" keyword to be a schema'); var ifValid = testSchemaNoThrow.call(this, instance, options, ctx, null, schema.if); var result = new ValidatorResult(instance, schema, options, ctx); var res; if (ifValid) { if (schema.then === void 0) return; if (!helpers.isSchema(schema.then)) throw new Error('Expected "then" keyword to be a schema'); res = this.validateSchema(instance, schema.then, options, ctx.makeChild(schema.then)); result.importErrors(res); } else { if (schema.else === void 0) return; if (!helpers.isSchema(schema.else)) throw new Error('Expected "else" keyword to be a schema'); res = this.validateSchema(instance, schema.else, options, ctx.makeChild(schema.else)); result.importErrors(res); } return result; }; function getEnumerableProperty(object, key) { if (Object.hasOwnProperty.call(object, key)) return object[key]; if (!(key in object)) return; while (object = Object.getPrototypeOf(object)) { if (Object.propertyIsEnumerable.call(object, key)) return object[key]; } } validators.propertyNames = function validatePropertyNames(instance, schema, options, ctx) { if (!this.types.object(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); var subschema = schema.propertyNames !== void 0 ? schema.propertyNames : {}; if (!helpers.isSchema(subschema)) throw new SchemaError('Expected "propertyNames" to be a schema (object or boolean)'); for (var property in instance) { if (getEnumerableProperty(instance, property) !== void 0) { var res = this.validateSchema(property, subschema, options, ctx.makeChild(subschema)); result.importErrors(res); } } return result; }; validators.properties = function validateProperties(instance, schema, options, ctx) { if (!this.types.object(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); var properties = schema.properties || {}; for (var property in properties) { var subschema = properties[property]; if (subschema === void 0) { continue; } else if (subschema === null) { throw new SchemaError('Unexpected null, expected schema in "properties"'); } if (typeof options.preValidateProperty == "function") { options.preValidateProperty(instance, property, subschema, options, ctx); } var prop = getEnumerableProperty(instance, property); var res = this.validateSchema(prop, subschema, options, ctx.makeChild(subschema, property)); if (res.instance !== result.instance[property]) result.instance[property] = res.instance; result.importErrors(res); } return result; }; function testAdditionalProperty(instance, schema, options, ctx, property, result) { if (!this.types.object(instance)) return; if (schema.properties && schema.properties[property] !== void 0) { return; } if (schema.additionalProperties === false) { result.addError({ name: "additionalProperties", argument: property, message: "is not allowed to have the additional property " + JSON.stringify(property) }); } else { var additionalProperties = schema.additionalProperties || {}; if (typeof options.preValidateProperty == "function") { options.preValidateProperty(instance, property, additionalProperties, options, ctx); } var res = this.validateSchema(instance[property], additionalProperties, options, ctx.makeChild(additionalProperties, property)); if (res.instance !== result.instance[property]) result.instance[property] = res.instance; result.importErrors(res); } } validators.patternProperties = function validatePatternProperties(instance, schema, options, ctx) { if (!this.types.object(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); var patternProperties = schema.patternProperties || {}; for (var property in instance) { var test = true; for (var pattern in patternProperties) { var subschema = patternProperties[pattern]; if (subschema === void 0) { continue; } else if (subschema === null) { throw new SchemaError('Unexpected null, expected schema in "patternProperties"'); } try { var regexp = new RegExp(pattern, "u"); } catch (_e) { regexp = new RegExp(pattern); } if (!regexp.test(property)) { continue; } test = false; if (typeof options.preValidateProperty == "function") { options.preValidateProperty(instance, property, subschema, options, ctx); } var res = this.validateSchema(instance[property], subschema, options, ctx.makeChild(subschema, property)); if (res.instance !== result.instance[property]) result.instance[property] = res.instance; result.importErrors(res); } if (test) { testAdditionalProperty.call(this, instance, schema, options, ctx, property, result); } } return result; }; validators.additionalProperties = function validateAdditionalProperties(instance, schema, options, ctx) { if (!this.types.object(instance)) return; if (schema.patternProperties) { return null; } var result = new ValidatorResult(instance, schema, options, ctx); for (var property in instance) { testAdditionalProperty.call(this, instance, schema, options, ctx, property, result); } return result; }; validators.minProperties = function validateMinProperties(instance, schema, options, ctx) { if (!this.types.object(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); var keys = Object.keys(instance); if (!(keys.length >= schema.minProperties)) { result.addError({ name: "minProperties", argument: schema.minProperties, message: "does not meet minimum property length of " + schema.minProperties }); } return result; }; validators.maxProperties = function validateMaxProperties(instance, schema, options, ctx) { if (!this.types.object(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); var keys = Object.keys(instance); if (!(keys.length <= schema.maxProperties)) { result.addError({ name: "maxProperties", argument: schema.maxProperties, message: "does not meet maximum property length of " + schema.maxProperties }); } return result; }; validators.items = function validateItems(instance, schema, options, ctx) { var self = this; if (!this.types.array(instance)) return; if (schema.items === void 0) return; var result = new ValidatorResult(instance, schema, options, ctx); instance.every(function(value, i) { if (Array.isArray(schema.items)) { var items = schema.items[i] === void 0 ? schema.additionalItems : schema.items[i]; } else { var items = schema.items; } if (items === void 0) { return true; } if (items === false) { result.addError({ name: "items", message: "additionalItems not permitted" }); return false; } var res = self.validateSchema(value, items, options, ctx.makeChild(items, i)); if (res.instance !== result.instance[i]) result.instance[i] = res.instance; result.importErrors(res); return true; }); return result; }; validators.contains = function validateContains(instance, schema, options, ctx) { var self = this; if (!this.types.array(instance)) return; if (schema.contains === void 0) return; if (!helpers.isSchema(schema.contains)) throw new Error('Expected "contains" keyword to be a schema'); var result = new ValidatorResult(instance, schema, options, ctx); var count = instance.some(function(value, i) { var res = self.validateSchema(value, schema.contains, options, ctx.makeChild(schema.contains, i)); return res.errors.length === 0; }); if (count === false) { result.addError({ name: "contains", argument: schema.contains, message: "must contain an item matching given schema" }); } return result; }; validators.minimum = function validateMinimum(instance, schema, options, ctx) { if (!this.types.number(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); if (schema.exclusiveMinimum && schema.exclusiveMinimum === true) { if (!(instance > schema.minimum)) { result.addError({ name: "minimum", argument: schema.minimum, message: "must be greater than " + schema.minimum }); } } else { if (!(instance >= schema.minimum)) { result.addError({ name: "minimum", argument: schema.minimum, message: "must be greater than or equal to " + schema.minimum }); } } return result; }; validators.maximum = function validateMaximum(instance, schema, options, ctx) { if (!this.types.number(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); if (schema.exclusiveMaximum && schema.exclusiveMaximum === true) { if (!(instance < schema.maximum)) { result.addError({ name: "maximum", argument: schema.maximum, message: "must be less than " + schema.maximum }); } } else { if (!(instance <= schema.maximum)) { result.addError({ name: "maximum", argument: schema.maximum, message: "must be less than or equal to " + schema.maximum }); } } return result; }; validators.exclusiveMinimum = function validateExclusiveMinimum(instance, schema, options, ctx) { if (typeof schema.exclusiveMinimum === "boolean") return; if (!this.types.number(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); var valid = instance > schema.exclusiveMinimum; if (!valid) { result.addError({ name: "exclusiveMinimum", argument: schema.exclusiveMinimum, message: "must be strictly greater than " + schema.exclusiveMinimum }); } return result; }; validators.exclusiveMaximum = function validateExclusiveMaximum(instance, schema, options, ctx) { if (typeof schema.exclusiveMaximum === "boolean") return; if (!this.types.number(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); var valid = instance < schema.exclusiveMaximum; if (!valid) { result.addError({ name: "exclusiveMaximum", argument: schema.exclusiveMaximum, message: "must be strictly less than " + schema.exclusiveMaximum }); } return result; }; var validateMultipleOfOrDivisbleBy = function validateMultipleOfOrDivisbleBy2(instance, schema, options, ctx, validationType, errorMessage) { if (!this.types.number(instance)) return; var validationArgument = schema[validationType]; if (validationArgument == 0) { throw new SchemaError(validationType + " cannot be zero"); } var result = new ValidatorResult(instance, schema, options, ctx); var instanceDecimals = helpers.getDecimalPlaces(instance); var divisorDecimals = helpers.getDecimalPlaces(validationArgument); var maxDecimals = Math.max(instanceDecimals, divisorDecimals); var multiplier = Math.pow(10, maxDecimals); if (Math.round(instance * multiplier) % Math.round(validationArgument * multiplier) !== 0) { result.addError({ name: validationType, argument: validationArgument, message: errorMessage + JSON.stringify(validationArgument) }); } return result; }; validators.multipleOf = function validateMultipleOf(instance, schema, options, ctx) { return validateMultipleOfOrDivisbleBy.call(this, instance, schema, options, ctx, "multipleOf", "is not a multiple of (divisible by) "); }; validators.divisibleBy = function validateDivisibleBy(instance, schema, options, ctx) { return validateMultipleOfOrDivisbleBy.call(this, instance, schema, options, ctx, "divisibleBy", "is not divisible by (multiple of) "); }; validators.required = function validateRequired(instance, schema, options, ctx) { var result = new ValidatorResult(instance, schema, options, ctx); if (instance === void 0 && schema.required === true) { result.addError({ name: "required", message: "is required" }); } else if (this.types.object(instance) && Array.isArray(schema.required)) { schema.required.forEach(function(n) { if (getEnumerableProperty(instance, n) === void 0) { result.addError({ name: "required", argument: n, message: "requires property " + JSON.stringify(n) }); } }); } return result; }; validators.pattern = function validatePattern(instance, schema, options, ctx) { if (!this.types.string(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); var pattern = schema.pattern; try { var regexp = new RegExp(pattern, "u"); } catch (_e) { regexp = new RegExp(pattern); } if (!instance.match(regexp)) { result.addError({ name: "pattern", argument: schema.pattern, message: "does not match pattern " + JSON.stringify(schema.pattern.toString()) }); } return result; }; validators.format = function validateFormat(instance, schema, options, ctx) { if (instance === void 0) return; var result = new ValidatorResult(instance, schema, options, ctx); if (!result.disableFormat && !helpers.isFormat(instance, schema.format, this)) { result.addError({ name: "format", argument: schema.format, message: "does not conform to the " + JSON.stringify(schema.format) + " format" }); } return result; }; validators.minLength = function validateMinLength(instance, schema, options, ctx) { if (!this.types.string(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); var hsp = instance.match(/[\uDC00-\uDFFF]/g); var length = instance.length - (hsp ? hsp.length : 0); if (!(length >= schema.minLength)) { result.addError({ name: "minLength", argument: schema.minLength, message: "does not meet minimum length of " + schema.minLength }); } return result; }; validators.maxLength = function validateMaxLength(instance, schema, options, ctx) { if (!this.types.string(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); var hsp = instance.match(/[\uDC00-\uDFFF]/g); var length = instance.length - (hsp ? hsp.length : 0); if (!(length <= schema.maxLength)) { result.addError({ name: "maxLength", argument: schema.maxLength, message: "does not meet maximum length of " + schema.maxLength }); } return result; }; validators.minItems = function validateMinItems(instance, schema, options, ctx) { if (!this.types.array(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); if (!(instance.length >= schema.minItems)) { result.addError({ name: "minItems", argument: schema.minItems, message: "does not meet minimum length of " + schema.minItems }); } return result; }; validators.maxItems = function validateMaxItems(instance, schema, options, ctx) { if (!this.types.array(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); if (!(instance.length <= schema.maxItems)) { result.addError({ name: "maxItems", argument: schema.maxItems, message: "does not meet maximum length of " + schema.maxItems }); } return result; }; function testArrays(v, i, a) { var j, len = a.length; for (j = i + 1, len; j < len; j++) { if (helpers.deepCompareStrict(v, a[j])) { return false; } } return true; } validators.uniqueItems = function validateUniqueItems(instance, schema, options, ctx) { if (schema.uniqueItems !== true) return; if (!this.types.array(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); if (!instance.every(testArrays)) { result.addError({ name: "uniqueItems", message: "contains duplicate item" }); } return result; }; validators.dependencies = function validateDependencies(instance, schema, options, ctx) { if (!this.types.object(instance)) return; var result = new ValidatorResult(instance, schema, options, ctx); for (var property in schema.dependencies) { if (instance[property] === void 0) { continue; } var dep = schema.dependencies[property]; var childContext = ctx.makeChild(dep, property); if (typeof dep == "string") { dep = [dep]; } if (Array.isArray(dep)) { dep.forEach(function(prop) { if (instance[prop] === void 0) { result.addError({ // FIXME there's two different "dependencies" errors here with slightly different outputs // Can we make these the same? Or should we create different error types? name: "dependencies", argument: childContext.propertyPath, message: "property " + prop + " not found, required by " + childContext.propertyPath }); } }); } else { var res = this.validateSchema(instance, dep, options, childContext); if (result.instance !== res.instance) result.instance = res.instance; if (res && res.errors.length) { result.addError({ name: "dependencies", argument: childContext.propertyPath, message: "does not meet dependency required by " + childContext.propertyPath }); result.importErrors(res); } } } return result; }; validators["enum"] = function validateEnum(instance, schema, options, ctx) { if (instance === void 0) { return null; } if (!Array.isArray(schema["enum"])) { throw new SchemaError("enum expects an array", schema); } var result = new ValidatorResult(instance, schema, options, ctx); if (!schema["enum"].some(helpers.deepCompareStrict.bind(null, instance))) { result.addError({ name: "enum", argument: schema["enum"], message: "is not one of enum values: " + schema["enum"].map(String).join(",") }); } return result; }; validators["const"] = function validateEnum(instance, schema, options, ctx) { if (instance === void 0) { return null; } var result = new ValidatorResult(instance, schema, options, ctx); if (!helpers.deepCompareStrict(schema["const"], instance)) { result.addError({ name: "const", argument: schema["const"], message: "does not exactly match expected constant: " + schema["const"] }); } return result; }; validators.not = validators.disallow = function validateNot(instance, schema, options, ctx) { var self = this; if (instance === void 0) return null; var result = new ValidatorResult(instance, schema, options, ctx); var notTypes = schema.not || schema.disallow; if (!notTypes) return null; if (!Array.isArray(notTypes)) notTypes = [notTypes]; notTypes.forEach(function(type) { if (self.testType(instance, schema, options, ctx, type)) { var id = type && (type.$id || type.id); var schemaId = id || type; result.addError({ name: "not", argument: schemaId, message: "is of prohibited type " + schemaId }); } }); return result; }; module.exports = attribute; } }); // node_modules/jsonschema/lib/scan.js var require_scan = __commonJS({ "node_modules/jsonschema/lib/scan.js"(exports, module) { "use strict"; var urilib = __require("url"); var helpers = require_helpers(); module.exports.SchemaScanResult = SchemaScanResult; function SchemaScanResult(found, ref) { this.id = found; this.ref = ref; } module.exports.scan = function scan(base, schema) { function scanSchema(baseuri, schema2) { if (!schema2 || typeof schema2 != "object") return; if (schema2.$ref) { var resolvedUri = urilib.resolve(baseuri, schema2.$ref); ref[resolvedUri] = ref[resolvedUri] ? ref[resolvedUri] + 1 : 0; return; } var id = schema2.$id || schema2.id; var ourBase = id ? urilib.resolve(baseuri, id) : baseuri; if (ourBase) { if (ourBase.indexOf("#") < 0) ourBase += "#"; if (found[ourBase]) { if (!helpers.deepCompareStrict(found[ourBase], schema2)) { throw new Error("Schema <" + ourBase + "> already exists with different definition"); } return found[ourBase]; } found[ourBase] = schema2; if (ourBase[ourBase.length - 1] == "#") { found[ourBase.substring(0, ourBase.length - 1)] = schema2; } } scanArray(ourBase + "/items", Array.isArray(schema2.items) ? schema2.items : [schema2.items]); scanArray(ourBase + "/extends", Array.isArray(schema2.extends) ? schema2.extends : [schema2.extends]); scanSchema(ourBase + "/additionalItems", schema2.additionalItems); scanObject(ourBase + "/properties", schema2.properties); scanSchema(ourBase + "/additionalProperties", schema2.additionalProperties); scanObject(ourBase + "/definitions", schema2.definitions); scanObject(ourBase + "/patternProperties", schema2.patternProperties); scanObject(ourBase + "/dependencies", schema2.dependencies); scanArray(ourBase + "/disallow", schema2.disallow); scanArray(ourBase + "/allOf", schema2.allOf); scanArray(ourBase + "/anyOf", schema2.anyOf); scanArray(ourBase + "/oneOf", schema2.oneOf); scanSchema(ourBase + "/not", schema2.not); } function scanArray(baseuri, schemas) { if (!Array.isArray(schemas)) return; for (var i = 0; i < schemas.length; i++) { scanSchema(baseuri + "/" + i, schemas[i]); } } function scanObject(baseuri, schemas) { if (!schemas || typeof schemas != "object") return; for (var p in schemas) { scanSchema(baseuri + "/" + p, schemas[p]); } } var found = {}; var ref = {}; scanSchema(base, schema); return new SchemaScanResult(found, ref); }; } }); // node_modules/jsonschema/lib/validator.js var require_validator = __commonJS({ "node_modules/jsonschema/lib/validator.js"(exports, module) { "use strict"; var urilib = __require("url"); var attribute = require_attribute(); var helpers = require_helpers(); var scanSchema = require_scan().scan; var ValidatorResult = helpers.ValidatorResult; var ValidatorResultError = helpers.ValidatorResultError; var SchemaError = helpers.SchemaError; var SchemaContext = helpers.SchemaContext; var anonymousBase = "/"; var Validator = function Validator2() { this.customFormats = Object.create(Validator2.prototype.customFormats); this.schemas = {}; this.unresolvedRefs = []; this.types = Object.create(ty