UNPKG

failure-lambda

Version:

Failure injection for AWS Lambda - chaos engineering made simple

1,400 lines (1,390 loc) 110 kB
#!/usr/bin/env node import { awsEndpointFunctions, package_default } from "./chunk-UQQPU6QH.js"; import { createAggregatedClient } from "./chunk-V4BSKZG7.js"; import { AwsSdkSigV4Signer, Client, Command, DEFAULT_RETRY_MODE, DefaultIdentityProviderConfig, EndpointCache, FromStringShapeDeserializer, Hash, HttpProtocol, NODE_APP_ID_CONFIG_OPTIONS, NODE_AUTH_SCHEME_PREFERENCE_OPTIONS, NODE_MAX_ATTEMPT_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS, NODE_REGION_CONFIG_OPTIONS, NODE_RETRY_MODE_CONFIG_OPTIONS, NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS, NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS, NoAuthSigner, NoOpLogger, NormalizedSchema, NumericValue, ProtocolLib, SerdeContextConfig, ServiceException, TypeRegistry, UnionSerde, calculateBodyLength, collectBody, createDefaultUserAgentProvider, customEndpointFunctions, deref, determineTimestampFormat, emitWarningIfUnsupportedVersion, emitWarningIfUnsupportedVersion2, extendedEncodeURIComponent, getAwsRegionExtensionConfiguration, getContentLengthPlugin, getDefaultExtensionConfiguration, getEndpointPlugin, getHostHeaderPlugin, getHttpAuthSchemeEndpointRuleSetPlugin, getHttpHandlerExtensionConfiguration, getHttpSigningPlugin, getLoggerPlugin, getRecursionDetectionPlugin, getRetryPlugin, getSchemaSerdePlugin, getSmithyContext, getUserAgentPlugin, loadConfigsForDefaultMode, normalizeProvider, resolveAwsRegionExtensionConfiguration, resolveAwsSdkSigV4Config, resolveDefaultRuntimeConfig, resolveDefaultsModeConfig, resolveEndpoint, resolveEndpointConfig, resolveHostHeaderConfig, resolveHttpHandlerRuntimeConfig, resolveRegionConfig, resolveRetryConfig, resolveUserAgentConfig, v4 } from "./chunk-762XZWE7.js"; import { loadConfig, parseUrl } from "./chunk-2345QE66.js"; import "./chunk-LILC4PLL.js"; import "./chunk-52D4AVIU.js"; import { NodeHttpHandler, dateToUtcString, fromBase64, streamCollector, toBase64 } from "./chunk-W3M6RT2M.js"; import { HttpRequest } from "./chunk-XDZ73E2B.js"; import { fromUtf8, toUtf8 } from "./chunk-VACN7GDP.js"; import { setCredentialFeature } from "./chunk-S6KKH4HA.js"; import "./chunk-M4AFYEP7.js"; import "./chunk-UT3JLF3M.js"; // node_modules/@smithy/core/dist-es/submodules/protocols/RpcProtocol.js var RpcProtocol = class extends HttpProtocol { async serializeRequest(operationSchema, input, context) { const serializer = this.serializer; const query = {}; const headers = {}; const endpoint = await context.endpoint(); const ns = NormalizedSchema.of(operationSchema?.input); const schema = ns.getSchema(); let payload; const request = new HttpRequest({ protocol: "", hostname: "", port: void 0, path: "/", fragment: void 0, query, headers, body: void 0 }); if (endpoint) { this.updateServiceEndpoint(request, endpoint); this.setHostPrefix(request, operationSchema, input); } const _input = { ...input }; if (input) { const eventStreamMember = ns.getEventStreamMember(); if (eventStreamMember) { if (_input[eventStreamMember]) { const initialRequest = {}; for (const [memberName, memberSchema] of ns.structIterator()) { if (memberName !== eventStreamMember && _input[memberName]) { serializer.write(memberSchema, _input[memberName]); initialRequest[memberName] = serializer.flush(); } } payload = await this.serializeEventStream({ eventStream: _input[eventStreamMember], requestSchema: ns, initialRequest }); } } else { serializer.write(schema, _input); payload = serializer.flush(); } } request.headers = headers; request.query = query; request.body = payload; request.method = "POST"; return request; } async deserializeResponse(operationSchema, context, response) { const deserializer = this.deserializer; const ns = NormalizedSchema.of(operationSchema.output); const dataObject = {}; if (response.statusCode >= 300) { const bytes = await collectBody(response.body, context); if (bytes.byteLength > 0) { Object.assign(dataObject, await deserializer.read(15, bytes)); } await this.handleError(operationSchema, context, response, dataObject, this.deserializeMetadata(response)); throw new Error("@smithy/core/protocols - RPC Protocol error handler failed to throw."); } for (const header in response.headers) { const value = response.headers[header]; delete response.headers[header]; response.headers[header.toLowerCase()] = value; } const eventStreamMember = ns.getEventStreamMember(); if (eventStreamMember) { dataObject[eventStreamMember] = await this.deserializeEventStream({ response, responseSchema: ns, initialResponseContainer: dataObject }); } else { const bytes = await collectBody(response.body, context); if (bytes.byteLength > 0) { Object.assign(dataObject, await deserializer.read(ns, bytes)); } } dataObject.$metadata = this.deserializeMetadata(response); return dataObject; } }; // node_modules/@smithy/smithy-client/dist-es/get-value-from-text-node.js var getValueFromTextNode = (obj) => { const textNodeName = "#text"; for (const key in obj) { if (obj.hasOwnProperty(key) && obj[key][textNodeName] !== void 0) { obj[key] = obj[key][textNodeName]; } else if (typeof obj[key] === "object" && obj[key] !== null) { obj[key] = getValueFromTextNode(obj[key]); } } return obj; }; // node_modules/fast-xml-parser/src/util.js var nameStartChar = ":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD"; var nameChar = nameStartChar + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040"; var nameRegexp = "[" + nameStartChar + "][" + nameChar + "]*"; var regexName = new RegExp("^" + nameRegexp + "$"); function getAllMatches(string, regex) { const matches = []; let match = regex.exec(string); while (match) { const allmatches = []; allmatches.startIndex = regex.lastIndex - match[0].length; const len = match.length; for (let index = 0; index < len; index++) { allmatches.push(match[index]); } matches.push(allmatches); match = regex.exec(string); } return matches; } var isName = function(string) { const match = regexName.exec(string); return !(match === null || typeof match === "undefined"); }; function isExist(v2) { return typeof v2 !== "undefined"; } // node_modules/fast-xml-parser/src/validator.js var defaultOptions = { allowBooleanAttributes: false, //A tag can have attributes without any value unpairedTags: [] }; function validate(xmlData, options) { options = Object.assign({}, defaultOptions, options); const tags = []; let tagFound = false; let reachedRoot = false; if (xmlData[0] === "\uFEFF") { xmlData = xmlData.substr(1); } for (let i2 = 0; i2 < xmlData.length; i2++) { if (xmlData[i2] === "<" && xmlData[i2 + 1] === "?") { i2 += 2; i2 = readPI(xmlData, i2); if (i2.err) return i2; } else if (xmlData[i2] === "<") { let tagStartPos = i2; i2++; if (xmlData[i2] === "!") { i2 = readCommentAndCDATA(xmlData, i2); continue; } else { let closingTag = false; if (xmlData[i2] === "/") { closingTag = true; i2++; } let tagName = ""; for (; i2 < xmlData.length && xmlData[i2] !== ">" && xmlData[i2] !== " " && xmlData[i2] !== " " && xmlData[i2] !== "\n" && xmlData[i2] !== "\r"; i2++) { tagName += xmlData[i2]; } tagName = tagName.trim(); if (tagName[tagName.length - 1] === "/") { tagName = tagName.substring(0, tagName.length - 1); i2--; } if (!validateTagName(tagName)) { let msg; if (tagName.trim().length === 0) { msg = "Invalid space after '<'."; } else { msg = "Tag '" + tagName + "' is an invalid name."; } return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i2)); } const result = readAttributeStr(xmlData, i2); if (result === false) { return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i2)); } let attrStr = result.value; i2 = result.index; if (attrStr[attrStr.length - 1] === "/") { const attrStrStart = i2 - attrStr.length; attrStr = attrStr.substring(0, attrStr.length - 1); const isValid = validateAttributeString(attrStr, options); if (isValid === true) { tagFound = true; } else { return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line)); } } else if (closingTag) { if (!result.tagClosed) { return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i2)); } else if (attrStr.trim().length > 0) { return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos)); } else if (tags.length === 0) { return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' has not been opened.", getLineNumberForPosition(xmlData, tagStartPos)); } else { const otg = tags.pop(); if (tagName !== otg.tagName) { let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos); return getErrorObject( "InvalidTag", "Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.", getLineNumberForPosition(xmlData, tagStartPos) ); } if (tags.length == 0) { reachedRoot = true; } } } else { const isValid = validateAttributeString(attrStr, options); if (isValid !== true) { return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i2 - attrStr.length + isValid.err.line)); } if (reachedRoot === true) { return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i2)); } else if (options.unpairedTags.indexOf(tagName) !== -1) { } else { tags.push({ tagName, tagStartPos }); } tagFound = true; } for (i2++; i2 < xmlData.length; i2++) { if (xmlData[i2] === "<") { if (xmlData[i2 + 1] === "!") { i2++; i2 = readCommentAndCDATA(xmlData, i2); continue; } else if (xmlData[i2 + 1] === "?") { i2 = readPI(xmlData, ++i2); if (i2.err) return i2; } else { break; } } else if (xmlData[i2] === "&") { const afterAmp = validateAmpersand(xmlData, i2); if (afterAmp == -1) return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i2)); i2 = afterAmp; } else { if (reachedRoot === true && !isWhiteSpace(xmlData[i2])) { return getErrorObject("InvalidXml", "Extra text at the end", getLineNumberForPosition(xmlData, i2)); } } } if (xmlData[i2] === "<") { i2--; } } } else { if (isWhiteSpace(xmlData[i2])) { continue; } return getErrorObject("InvalidChar", "char '" + xmlData[i2] + "' is not expected.", getLineNumberForPosition(xmlData, i2)); } } if (!tagFound) { return getErrorObject("InvalidXml", "Start tag expected.", 1); } else if (tags.length == 1) { return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos)); } else if (tags.length > 0) { return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t2) => t2.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 }); } return true; } function isWhiteSpace(char) { return char === " " || char === " " || char === "\n" || char === "\r"; } function readPI(xmlData, i2) { const start = i2; for (; i2 < xmlData.length; i2++) { if (xmlData[i2] == "?" || xmlData[i2] == " ") { const tagname = xmlData.substr(start, i2 - start); if (i2 > 5 && tagname === "xml") { return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i2)); } else if (xmlData[i2] == "?" && xmlData[i2 + 1] == ">") { i2++; break; } else { continue; } } } return i2; } function readCommentAndCDATA(xmlData, i2) { if (xmlData.length > i2 + 5 && xmlData[i2 + 1] === "-" && xmlData[i2 + 2] === "-") { for (i2 += 3; i2 < xmlData.length; i2++) { if (xmlData[i2] === "-" && xmlData[i2 + 1] === "-" && xmlData[i2 + 2] === ">") { i2 += 2; break; } } } else if (xmlData.length > i2 + 8 && xmlData[i2 + 1] === "D" && xmlData[i2 + 2] === "O" && xmlData[i2 + 3] === "C" && xmlData[i2 + 4] === "T" && xmlData[i2 + 5] === "Y" && xmlData[i2 + 6] === "P" && xmlData[i2 + 7] === "E") { let angleBracketsCount = 1; for (i2 += 8; i2 < xmlData.length; i2++) { if (xmlData[i2] === "<") { angleBracketsCount++; } else if (xmlData[i2] === ">") { angleBracketsCount--; if (angleBracketsCount === 0) { break; } } } } else if (xmlData.length > i2 + 9 && xmlData[i2 + 1] === "[" && xmlData[i2 + 2] === "C" && xmlData[i2 + 3] === "D" && xmlData[i2 + 4] === "A" && xmlData[i2 + 5] === "T" && xmlData[i2 + 6] === "A" && xmlData[i2 + 7] === "[") { for (i2 += 8; i2 < xmlData.length; i2++) { if (xmlData[i2] === "]" && xmlData[i2 + 1] === "]" && xmlData[i2 + 2] === ">") { i2 += 2; break; } } } return i2; } var doubleQuote = '"'; var singleQuote = "'"; function readAttributeStr(xmlData, i2) { let attrStr = ""; let startChar = ""; let tagClosed = false; for (; i2 < xmlData.length; i2++) { if (xmlData[i2] === doubleQuote || xmlData[i2] === singleQuote) { if (startChar === "") { startChar = xmlData[i2]; } else if (startChar !== xmlData[i2]) { } else { startChar = ""; } } else if (xmlData[i2] === ">") { if (startChar === "") { tagClosed = true; break; } } attrStr += xmlData[i2]; } if (startChar !== "") { return false; } return { value: attrStr, index: i2, tagClosed }; } var validAttrStrRegxp = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g"); function validateAttributeString(attrStr, options) { const matches = getAllMatches(attrStr, validAttrStrRegxp); const attrNames = {}; for (let i2 = 0; i2 < matches.length; i2++) { if (matches[i2][1].length === 0) { return getErrorObject("InvalidAttr", "Attribute '" + matches[i2][2] + "' has no space in starting.", getPositionFromMatch(matches[i2])); } else if (matches[i2][3] !== void 0 && matches[i2][4] === void 0) { return getErrorObject("InvalidAttr", "Attribute '" + matches[i2][2] + "' is without value.", getPositionFromMatch(matches[i2])); } else if (matches[i2][3] === void 0 && !options.allowBooleanAttributes) { return getErrorObject("InvalidAttr", "boolean attribute '" + matches[i2][2] + "' is not allowed.", getPositionFromMatch(matches[i2])); } const attrName = matches[i2][2]; if (!validateAttrName(attrName)) { return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i2])); } if (!attrNames.hasOwnProperty(attrName)) { attrNames[attrName] = 1; } else { return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i2])); } } return true; } function validateNumberAmpersand(xmlData, i2) { let re = /\d/; if (xmlData[i2] === "x") { i2++; re = /[\da-fA-F]/; } for (; i2 < xmlData.length; i2++) { if (xmlData[i2] === ";") return i2; if (!xmlData[i2].match(re)) break; } return -1; } function validateAmpersand(xmlData, i2) { i2++; if (xmlData[i2] === ";") return -1; if (xmlData[i2] === "#") { i2++; return validateNumberAmpersand(xmlData, i2); } let count = 0; for (; i2 < xmlData.length; i2++, count++) { if (xmlData[i2].match(/\w/) && count < 20) continue; if (xmlData[i2] === ";") break; return -1; } return i2; } function getErrorObject(code, message, lineNumber) { return { err: { code, msg: message, line: lineNumber.line || lineNumber, col: lineNumber.col } }; } function validateAttrName(attrName) { return isName(attrName); } function validateTagName(tagname) { return isName(tagname); } function getLineNumberForPosition(xmlData, index) { const lines = xmlData.substring(0, index).split(/\r?\n/); return { line: lines.length, // column number is last line's length + 1, because column numbering starts at 1: col: lines[lines.length - 1].length + 1 }; } function getPositionFromMatch(match) { return match.startIndex + match[1].length; } // node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js var defaultOptions2 = { preserveOrder: false, attributeNamePrefix: "@_", attributesGroupName: false, textNodeName: "#text", ignoreAttributes: true, removeNSPrefix: false, // remove NS from tag name or attribute name if true allowBooleanAttributes: false, //a tag can have attributes without any value //ignoreRootElement : false, parseTagValue: true, parseAttributeValue: false, trimValues: true, //Trim string values of tag and attributes cdataPropName: false, numberParseOptions: { hex: true, leadingZeros: true, eNotation: true }, tagValueProcessor: function(tagName, val) { return val; }, attributeValueProcessor: function(attrName, val) { return val; }, stopNodes: [], //nested tags will not be parsed even for errors alwaysCreateTextNode: false, isArray: () => false, commentPropName: false, unpairedTags: [], processEntities: true, htmlEntities: false, ignoreDeclaration: false, ignorePiTags: false, transformTagName: false, transformAttributeName: false, updateTag: function(tagName, jPath, attrs) { return tagName; }, // skipEmptyListItem: false captureMetaData: false }; function normalizeProcessEntities(value) { if (typeof value === "boolean") { return { enabled: value, // true or false maxEntitySize: 1e4, maxExpansionDepth: 10, maxTotalExpansions: 1e3, maxExpandedLength: 1e5, allowedTags: null, tagFilter: null }; } if (typeof value === "object" && value !== null) { return { enabled: value.enabled !== false, // default true if not specified maxEntitySize: value.maxEntitySize ?? 1e4, maxExpansionDepth: value.maxExpansionDepth ?? 10, maxTotalExpansions: value.maxTotalExpansions ?? 1e3, maxExpandedLength: value.maxExpandedLength ?? 1e5, allowedTags: value.allowedTags ?? null, tagFilter: value.tagFilter ?? null }; } return normalizeProcessEntities(true); } var buildOptions = function(options) { const built = Object.assign({}, defaultOptions2, options); built.processEntities = normalizeProcessEntities(built.processEntities); return built; }; // node_modules/fast-xml-parser/src/xmlparser/xmlNode.js var METADATA_SYMBOL; if (typeof Symbol !== "function") { METADATA_SYMBOL = "@@xmlMetadata"; } else { METADATA_SYMBOL = /* @__PURE__ */ Symbol("XML Node Metadata"); } var XmlNode = class { constructor(tagname) { this.tagname = tagname; this.child = []; this[":@"] = {}; } add(key, val) { if (key === "__proto__") key = "#__proto__"; this.child.push({ [key]: val }); } addChild(node, startIndex) { if (node.tagname === "__proto__") node.tagname = "#__proto__"; if (node[":@"] && Object.keys(node[":@"]).length > 0) { this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] }); } else { this.child.push({ [node.tagname]: node.child }); } if (startIndex !== void 0) { this.child[this.child.length - 1][METADATA_SYMBOL] = { startIndex }; } } /** symbol used for metadata */ static getMetaDataSymbol() { return METADATA_SYMBOL; } }; // node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js var DocTypeReader = class { constructor(options) { this.suppressValidationErr = !options; this.options = options; } readDocType(xmlData, i2) { const entities = {}; if (xmlData[i2 + 3] === "O" && xmlData[i2 + 4] === "C" && xmlData[i2 + 5] === "T" && xmlData[i2 + 6] === "Y" && xmlData[i2 + 7] === "P" && xmlData[i2 + 8] === "E") { i2 = i2 + 9; let angleBracketsCount = 1; let hasBody = false, comment = false; let exp = ""; for (; i2 < xmlData.length; i2++) { if (xmlData[i2] === "<" && !comment) { if (hasBody && hasSeq(xmlData, "!ENTITY", i2)) { i2 += 7; let entityName, val; [entityName, val, i2] = this.readEntityExp(xmlData, i2 + 1, this.suppressValidationErr); if (val.indexOf("&") === -1) { const escaped = entityName.replace(/[.\-+*:]/g, "\\."); entities[entityName] = { regx: RegExp(`&${escaped};`, "g"), val }; } } else if (hasBody && hasSeq(xmlData, "!ELEMENT", i2)) { i2 += 8; const { index } = this.readElementExp(xmlData, i2 + 1); i2 = index; } else if (hasBody && hasSeq(xmlData, "!ATTLIST", i2)) { i2 += 8; } else if (hasBody && hasSeq(xmlData, "!NOTATION", i2)) { i2 += 9; const { index } = this.readNotationExp(xmlData, i2 + 1, this.suppressValidationErr); i2 = index; } else if (hasSeq(xmlData, "!--", i2)) comment = true; else throw new Error(`Invalid DOCTYPE`); angleBracketsCount++; exp = ""; } else if (xmlData[i2] === ">") { if (comment) { if (xmlData[i2 - 1] === "-" && xmlData[i2 - 2] === "-") { comment = false; angleBracketsCount--; } } else { angleBracketsCount--; } if (angleBracketsCount === 0) { break; } } else if (xmlData[i2] === "[") { hasBody = true; } else { exp += xmlData[i2]; } } if (angleBracketsCount !== 0) { throw new Error(`Unclosed DOCTYPE`); } } else { throw new Error(`Invalid Tag instead of DOCTYPE`); } return { entities, i: i2 }; } readEntityExp(xmlData, i2) { i2 = skipWhitespace(xmlData, i2); let entityName = ""; while (i2 < xmlData.length && !/\s/.test(xmlData[i2]) && xmlData[i2] !== '"' && xmlData[i2] !== "'") { entityName += xmlData[i2]; i2++; } validateEntityName(entityName); i2 = skipWhitespace(xmlData, i2); if (!this.suppressValidationErr) { if (xmlData.substring(i2, i2 + 6).toUpperCase() === "SYSTEM") { throw new Error("External entities are not supported"); } else if (xmlData[i2] === "%") { throw new Error("Parameter entities are not supported"); } } let entityValue = ""; [i2, entityValue] = this.readIdentifierVal(xmlData, i2, "entity"); if (this.options.enabled !== false && this.options.maxEntitySize && entityValue.length > this.options.maxEntitySize) { throw new Error( `Entity "${entityName}" size (${entityValue.length}) exceeds maximum allowed size (${this.options.maxEntitySize})` ); } i2--; return [entityName, entityValue, i2]; } readNotationExp(xmlData, i2) { i2 = skipWhitespace(xmlData, i2); let notationName = ""; while (i2 < xmlData.length && !/\s/.test(xmlData[i2])) { notationName += xmlData[i2]; i2++; } !this.suppressValidationErr && validateEntityName(notationName); i2 = skipWhitespace(xmlData, i2); const identifierType = xmlData.substring(i2, i2 + 6).toUpperCase(); if (!this.suppressValidationErr && identifierType !== "SYSTEM" && identifierType !== "PUBLIC") { throw new Error(`Expected SYSTEM or PUBLIC, found "${identifierType}"`); } i2 += identifierType.length; i2 = skipWhitespace(xmlData, i2); let publicIdentifier = null; let systemIdentifier = null; if (identifierType === "PUBLIC") { [i2, publicIdentifier] = this.readIdentifierVal(xmlData, i2, "publicIdentifier"); i2 = skipWhitespace(xmlData, i2); if (xmlData[i2] === '"' || xmlData[i2] === "'") { [i2, systemIdentifier] = this.readIdentifierVal(xmlData, i2, "systemIdentifier"); } } else if (identifierType === "SYSTEM") { [i2, systemIdentifier] = this.readIdentifierVal(xmlData, i2, "systemIdentifier"); if (!this.suppressValidationErr && !systemIdentifier) { throw new Error("Missing mandatory system identifier for SYSTEM notation"); } } return { notationName, publicIdentifier, systemIdentifier, index: --i2 }; } readIdentifierVal(xmlData, i2, type) { let identifierVal = ""; const startChar = xmlData[i2]; if (startChar !== '"' && startChar !== "'") { throw new Error(`Expected quoted string, found "${startChar}"`); } i2++; while (i2 < xmlData.length && xmlData[i2] !== startChar) { identifierVal += xmlData[i2]; i2++; } if (xmlData[i2] !== startChar) { throw new Error(`Unterminated ${type} value`); } i2++; return [i2, identifierVal]; } readElementExp(xmlData, i2) { i2 = skipWhitespace(xmlData, i2); let elementName = ""; while (i2 < xmlData.length && !/\s/.test(xmlData[i2])) { elementName += xmlData[i2]; i2++; } if (!this.suppressValidationErr && !isName(elementName)) { throw new Error(`Invalid element name: "${elementName}"`); } i2 = skipWhitespace(xmlData, i2); let contentModel = ""; if (xmlData[i2] === "E" && hasSeq(xmlData, "MPTY", i2)) i2 += 4; else if (xmlData[i2] === "A" && hasSeq(xmlData, "NY", i2)) i2 += 2; else if (xmlData[i2] === "(") { i2++; while (i2 < xmlData.length && xmlData[i2] !== ")") { contentModel += xmlData[i2]; i2++; } if (xmlData[i2] !== ")") { throw new Error("Unterminated content model"); } } else if (!this.suppressValidationErr) { throw new Error(`Invalid Element Expression, found "${xmlData[i2]}"`); } return { elementName, contentModel: contentModel.trim(), index: i2 }; } readAttlistExp(xmlData, i2) { i2 = skipWhitespace(xmlData, i2); let elementName = ""; while (i2 < xmlData.length && !/\s/.test(xmlData[i2])) { elementName += xmlData[i2]; i2++; } validateEntityName(elementName); i2 = skipWhitespace(xmlData, i2); let attributeName = ""; while (i2 < xmlData.length && !/\s/.test(xmlData[i2])) { attributeName += xmlData[i2]; i2++; } if (!validateEntityName(attributeName)) { throw new Error(`Invalid attribute name: "${attributeName}"`); } i2 = skipWhitespace(xmlData, i2); let attributeType = ""; if (xmlData.substring(i2, i2 + 8).toUpperCase() === "NOTATION") { attributeType = "NOTATION"; i2 += 8; i2 = skipWhitespace(xmlData, i2); if (xmlData[i2] !== "(") { throw new Error(`Expected '(', found "${xmlData[i2]}"`); } i2++; let allowedNotations = []; while (i2 < xmlData.length && xmlData[i2] !== ")") { let notation = ""; while (i2 < xmlData.length && xmlData[i2] !== "|" && xmlData[i2] !== ")") { notation += xmlData[i2]; i2++; } notation = notation.trim(); if (!validateEntityName(notation)) { throw new Error(`Invalid notation name: "${notation}"`); } allowedNotations.push(notation); if (xmlData[i2] === "|") { i2++; i2 = skipWhitespace(xmlData, i2); } } if (xmlData[i2] !== ")") { throw new Error("Unterminated list of notations"); } i2++; attributeType += " (" + allowedNotations.join("|") + ")"; } else { while (i2 < xmlData.length && !/\s/.test(xmlData[i2])) { attributeType += xmlData[i2]; i2++; } const validTypes = ["CDATA", "ID", "IDREF", "IDREFS", "ENTITY", "ENTITIES", "NMTOKEN", "NMTOKENS"]; if (!this.suppressValidationErr && !validTypes.includes(attributeType.toUpperCase())) { throw new Error(`Invalid attribute type: "${attributeType}"`); } } i2 = skipWhitespace(xmlData, i2); let defaultValue = ""; if (xmlData.substring(i2, i2 + 8).toUpperCase() === "#REQUIRED") { defaultValue = "#REQUIRED"; i2 += 8; } else if (xmlData.substring(i2, i2 + 7).toUpperCase() === "#IMPLIED") { defaultValue = "#IMPLIED"; i2 += 7; } else { [i2, defaultValue] = this.readIdentifierVal(xmlData, i2, "ATTLIST"); } return { elementName, attributeName, attributeType, defaultValue, index: i2 }; } }; var skipWhitespace = (data, index) => { while (index < data.length && /\s/.test(data[index])) { index++; } return index; }; function hasSeq(data, seq, i2) { for (let j2 = 0; j2 < seq.length; j2++) { if (seq[j2] !== data[i2 + j2 + 1]) return false; } return true; } function validateEntityName(name) { if (isName(name)) return name; else throw new Error(`Invalid entity name ${name}`); } // node_modules/strnum/strnum.js var hexRegex = /^[-+]?0x[a-fA-F0-9]+$/; var numRegex = /^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/; var consider = { hex: true, // oct: false, leadingZeros: true, decimalPoint: ".", eNotation: true //skipLike: /regex/ }; function toNumber(str, options = {}) { options = Object.assign({}, consider, options); if (!str || typeof str !== "string") return str; let trimmedStr = str.trim(); if (options.skipLike !== void 0 && options.skipLike.test(trimmedStr)) return str; else if (str === "0") return 0; else if (options.hex && hexRegex.test(trimmedStr)) { return parse_int(trimmedStr, 16); } else if (trimmedStr.includes("e") || trimmedStr.includes("E")) { return resolveEnotation(str, trimmedStr, options); } else { const match = numRegex.exec(trimmedStr); if (match) { const sign = match[1] || ""; const leadingZeros = match[2]; let numTrimmedByZeros = trimZeros(match[3]); const decimalAdjacentToLeadingZeros = sign ? ( // 0., -00., 000. str[leadingZeros.length + 1] === "." ) : str[leadingZeros.length] === "."; if (!options.leadingZeros && (leadingZeros.length > 1 || leadingZeros.length === 1 && !decimalAdjacentToLeadingZeros)) { return str; } else { const num = Number(trimmedStr); const parsedStr = String(num); if (num === 0) return num; if (parsedStr.search(/[eE]/) !== -1) { if (options.eNotation) return num; else return str; } else if (trimmedStr.indexOf(".") !== -1) { if (parsedStr === "0") return num; else if (parsedStr === numTrimmedByZeros) return num; else if (parsedStr === `${sign}${numTrimmedByZeros}`) return num; else return str; } let n2 = leadingZeros ? numTrimmedByZeros : trimmedStr; if (leadingZeros) { return n2 === parsedStr || sign + n2 === parsedStr ? num : str; } else { return n2 === parsedStr || n2 === sign + parsedStr ? num : str; } } } else { return str; } } } var eNotationRegx = /^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/; function resolveEnotation(str, trimmedStr, options) { if (!options.eNotation) return str; const notation = trimmedStr.match(eNotationRegx); if (notation) { let sign = notation[1] || ""; const eChar = notation[3].indexOf("e") === -1 ? "E" : "e"; const leadingZeros = notation[2]; const eAdjacentToLeadingZeros = sign ? ( // 0E. str[leadingZeros.length + 1] === eChar ) : str[leadingZeros.length] === eChar; if (leadingZeros.length > 1 && eAdjacentToLeadingZeros) return str; else if (leadingZeros.length === 1 && (notation[3].startsWith(`.${eChar}`) || notation[3][0] === eChar)) { return Number(trimmedStr); } else if (options.leadingZeros && !eAdjacentToLeadingZeros) { trimmedStr = (notation[1] || "") + notation[3]; return Number(trimmedStr); } else return str; } else { return str; } } function trimZeros(numStr) { if (numStr && numStr.indexOf(".") !== -1) { numStr = numStr.replace(/0+$/, ""); if (numStr === ".") numStr = "0"; else if (numStr[0] === ".") numStr = "0" + numStr; else if (numStr[numStr.length - 1] === ".") numStr = numStr.substring(0, numStr.length - 1); return numStr; } return numStr; } function parse_int(numStr, base) { if (parseInt) return parseInt(numStr, base); else if (Number.parseInt) return Number.parseInt(numStr, base); else if (window && window.parseInt) return window.parseInt(numStr, base); else throw new Error("parseInt, Number.parseInt, window.parseInt are not supported"); } // node_modules/fast-xml-parser/src/ignoreAttributes.js function getIgnoreAttributesFn(ignoreAttributes) { if (typeof ignoreAttributes === "function") { return ignoreAttributes; } if (Array.isArray(ignoreAttributes)) { return (attrName) => { for (const pattern of ignoreAttributes) { if (typeof pattern === "string" && attrName === pattern) { return true; } if (pattern instanceof RegExp && pattern.test(attrName)) { return true; } } }; } return () => false; } // node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js var OrderedObjParser = class { constructor(options) { this.options = options; this.currentNode = null; this.tagsNodeStack = []; this.docTypeEntities = {}; this.lastEntities = { "apos": { regex: /&(apos|#39|#x27);/g, val: "'" }, "gt": { regex: /&(gt|#62|#x3E);/g, val: ">" }, "lt": { regex: /&(lt|#60|#x3C);/g, val: "<" }, "quot": { regex: /&(quot|#34|#x22);/g, val: '"' } }; this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" }; this.htmlEntities = { "space": { regex: /&(nbsp|#160);/g, val: " " }, // "lt" : { regex: /&(lt|#60);/g, val: "<" }, // "gt" : { regex: /&(gt|#62);/g, val: ">" }, // "amp" : { regex: /&(amp|#38);/g, val: "&" }, // "quot" : { regex: /&(quot|#34);/g, val: "\"" }, // "apos" : { regex: /&(apos|#39);/g, val: "'" }, "cent": { regex: /&(cent|#162);/g, val: "\xA2" }, "pound": { regex: /&(pound|#163);/g, val: "\xA3" }, "yen": { regex: /&(yen|#165);/g, val: "\xA5" }, "euro": { regex: /&(euro|#8364);/g, val: "\u20AC" }, "copyright": { regex: /&(copy|#169);/g, val: "\xA9" }, "reg": { regex: /&(reg|#174);/g, val: "\xAE" }, "inr": { regex: /&(inr|#8377);/g, val: "\u20B9" }, "num_dec": { regex: /&#([0-9]{1,7});/g, val: (_, str) => fromCodePoint(str, 10, "&#") }, "num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val: (_, str) => fromCodePoint(str, 16, "&#x") } }; this.addExternalEntities = addExternalEntities; this.parseXml = parseXml; this.parseTextData = parseTextData; this.resolveNameSpace = resolveNameSpace; this.buildAttributesMap = buildAttributesMap; this.isItStopNode = isItStopNode; this.replaceEntitiesValue = replaceEntitiesValue; this.readStopNodeData = readStopNodeData; this.saveTextToParentTag = saveTextToParentTag; this.addChild = addChild; this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes); this.entityExpansionCount = 0; this.currentExpandedLength = 0; if (this.options.stopNodes && this.options.stopNodes.length > 0) { this.stopNodesExact = /* @__PURE__ */ new Set(); this.stopNodesWildcard = /* @__PURE__ */ new Set(); for (let i2 = 0; i2 < this.options.stopNodes.length; i2++) { const stopNodeExp = this.options.stopNodes[i2]; if (typeof stopNodeExp !== "string") continue; if (stopNodeExp.startsWith("*.")) { this.stopNodesWildcard.add(stopNodeExp.substring(2)); } else { this.stopNodesExact.add(stopNodeExp); } } } } }; function addExternalEntities(externalEntities) { const entKeys = Object.keys(externalEntities); for (let i2 = 0; i2 < entKeys.length; i2++) { const ent = entKeys[i2]; const escaped = ent.replace(/[.\-+*:]/g, "\\."); this.lastEntities[ent] = { regex: new RegExp("&" + escaped + ";", "g"), val: externalEntities[ent] }; } } function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) { if (val !== void 0) { if (this.options.trimValues && !dontTrim) { val = val.trim(); } if (val.length > 0) { if (!escapeEntities) val = this.replaceEntitiesValue(val, tagName, jPath); const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode); if (newval === null || newval === void 0) { return val; } else if (typeof newval !== typeof val || newval !== val) { return newval; } else if (this.options.trimValues) { return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions); } else { const trimmedVal = val.trim(); if (trimmedVal === val) { return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions); } else { return val; } } } } } function resolveNameSpace(tagname) { if (this.options.removeNSPrefix) { const tags = tagname.split(":"); const prefix = tagname.charAt(0) === "/" ? "/" : ""; if (tags[0] === "xmlns") { return ""; } if (tags.length === 2) { tagname = prefix + tags[1]; } } return tagname; } var attrsRegx = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm"); function buildAttributesMap(attrStr, jPath, tagName) { if (this.options.ignoreAttributes !== true && typeof attrStr === "string") { const matches = getAllMatches(attrStr, attrsRegx); const len = matches.length; const attrs = {}; for (let i2 = 0; i2 < len; i2++) { const attrName = this.resolveNameSpace(matches[i2][1]); if (this.ignoreAttributesFn(attrName, jPath)) { continue; } let oldVal = matches[i2][4]; let aName = this.options.attributeNamePrefix + attrName; if (attrName.length) { if (this.options.transformAttributeName) { aName = this.options.transformAttributeName(aName); } if (aName === "__proto__") aName = "#__proto__"; if (oldVal !== void 0) { if (this.options.trimValues) { oldVal = oldVal.trim(); } oldVal = this.replaceEntitiesValue(oldVal, tagName, jPath); const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath); if (newVal === null || newVal === void 0) { attrs[aName] = oldVal; } else if (typeof newVal !== typeof oldVal || newVal !== oldVal) { attrs[aName] = newVal; } else { attrs[aName] = parseValue( oldVal, this.options.parseAttributeValue, this.options.numberParseOptions ); } } else if (this.options.allowBooleanAttributes) { attrs[aName] = true; } } } if (!Object.keys(attrs).length) { return; } if (this.options.attributesGroupName) { const attrCollection = {}; attrCollection[this.options.attributesGroupName] = attrs; return attrCollection; } return attrs; } } var parseXml = function(xmlData) { xmlData = xmlData.replace(/\r\n?/g, "\n"); const xmlObj = new XmlNode("!xml"); let currentNode = xmlObj; let textData = ""; let jPath = ""; this.entityExpansionCount = 0; this.currentExpandedLength = 0; const docTypeReader = new DocTypeReader(this.options.processEntities); for (let i2 = 0; i2 < xmlData.length; i2++) { const ch = xmlData[i2]; if (ch === "<") { if (xmlData[i2 + 1] === "/") { const closeIndex = findClosingIndex(xmlData, ">", i2, "Closing Tag is not closed."); let tagName = xmlData.substring(i2 + 2, closeIndex).trim(); if (this.options.removeNSPrefix) { const colonIndex = tagName.indexOf(":"); if (colonIndex !== -1) { tagName = tagName.substr(colonIndex + 1); } } if (this.options.transformTagName) { tagName = this.options.transformTagName(tagName); } if (currentNode) { textData = this.saveTextToParentTag(textData, currentNode, jPath); } const lastTagName = jPath.substring(jPath.lastIndexOf(".") + 1); if (tagName && this.options.unpairedTags.indexOf(tagName) !== -1) { throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`); } let propIndex = 0; if (lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1) { propIndex = jPath.lastIndexOf(".", jPath.lastIndexOf(".") - 1); this.tagsNodeStack.pop(); } else { propIndex = jPath.lastIndexOf("."); } jPath = jPath.substring(0, propIndex); currentNode = this.tagsNodeStack.pop(); textData = ""; i2 = closeIndex; } else if (xmlData[i2 + 1] === "?") { let tagData = readTagExp(xmlData, i2, false, "?>"); if (!tagData) throw new Error("Pi Tag is not closed."); textData = this.saveTextToParentTag(textData, currentNode, jPath); if (this.options.ignoreDeclaration && tagData.tagName === "?xml" || this.options.ignorePiTags) { } else { const childNode = new XmlNode(tagData.tagName); childNode.add(this.options.textNodeName, ""); if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) { childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName); } this.addChild(currentNode, childNode, jPath, i2); } i2 = tagData.closeIndex + 1; } else if (xmlData.substr(i2 + 1, 3) === "!--") { const endIndex = findClosingIndex(xmlData, "-->", i2 + 4, "Comment is not closed."); if (this.options.commentPropName) { const comment = xmlData.substring(i2 + 4, endIndex - 2); textData = this.saveTextToParentTag(textData, currentNode, jPath); currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]); } i2 = endIndex; } else if (xmlData.substr(i2 + 1, 2) === "!D") { const result = docTypeReader.readDocType(xmlData, i2); this.docTypeEntities = result.entities; i2 = result.i; } else if (xmlData.substr(i2 + 1, 2) === "![") { const closeIndex = findClosingIndex(xmlData, "]]>", i2, "CDATA is not closed.") - 2; const tagExp = xmlData.substring(i2 + 9, closeIndex); textData = this.saveTextToParentTag(textData, currentNode, jPath); let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true); if (val == void 0) val = ""; if (this.options.cdataPropName) { currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]); } else { currentNode.add(this.options.textNodeName, val); } i2 = closeIndex + 2; } else { let result = readTagExp(xmlData, i2, this.options.removeNSPrefix); let tagName = result.tagName; const rawTagName = result.rawTagName; let tagExp = result.tagExp; let attrExpPresent = result.attrExpPresent; let closeIndex = result.closeIndex; if (this.options.transformTagName) { const newTagName = this.options.transformTagName(tagName); if (tagExp === tagName) { tagExp = newTagName; } tagName = newTagName; } if (currentNode && textData) { if (currentNode.tagname !== "!xml") { textData = this.saveTextToParentTag(textData, currentNode, jPath, false); } } const lastTag = currentNode; if (lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1) { currentNode = this.tagsNodeStack.pop(); jPath = jPath.substring(0, jPath.lastIndexOf(".")); } if (tagName !== xmlObj.tagname) { jPath += jPath ? "." + tagName : tagName; } const startIndex = i2; if (this.isItStopNode(this.stopNodesExact, this.stopNodesWildcard, jPath, tagName)) { let tagContent = ""; if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) { if (tagName[tagName.length - 1] === "/") { tagName = tagName.substr(0, tagName.length - 1); jPath = jPath.substr(0, jPath.length - 1); tagExp = tagName; } else { tagExp = tagExp.substr(0, tagExp.length - 1); } i2 = result.closeIndex; } else if (this.options.unpairedTags.indexOf(tagName) !== -1) { i2 = result.closeIndex; } else { const result2 = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1); if (!result2) throw new Error(`Unexpected end of ${rawTagName}`); i2 = result2.i; tagContent = result2.tagContent; } const childNode = new XmlNode(tagName); if (tagName !== tagExp && attrExpPresent) { childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName); } if (tagContent) { tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true); } jPath = jPath.substr(0, jPath.lastIndexOf(".")); childNode.add(this.options.textNodeName, tagContent); this.addChild(currentNode, childNode, jPath, startIndex); } else { if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) { if (tagName[tagName.length - 1] === "/") { tagName = tagName.substr(0, tagName.length - 1); jPath = jPath.substr(0, jPath.length - 1); tagExp = tagName; } else { tagExp = tagExp.substr(0, tagExp.length - 1); } if (this.options.transformTagName) { const newTagName = this.options.transformTagName(tagName); if (tagExp === tagName) { tagExp = newTagName; } tagName = newTagName; } const childNode = new XmlNode(tagName); if (tagName !== tagExp && attrExpPresent) { childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName); } this.addChild(currentNode, childNode, jPath, startIndex); jPath = jPath.substr(0, jPath.lastIndexOf(".")); } else { const childNode = new XmlNode(tagName); this.tagsNodeStack.push(currentNode); if (tagName !== tagExp && attrExpPresent) { childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName); } this.addChild(currentNode, childNode, jPath, startIndex); currentNode = childNode; } textData = ""; i2 = closeIndex; } } } else { textData += xmlData[i2]; } } return xmlObj.child; }; function addChild(currentNode, childNode, jPath, startIndex) { if (!this.options.captureMetaData) startIndex = void 0; const result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"]); if (result === false) { } else if (typeof result === "string") { childNode.tagname = result; currentNode.addChild(childNode, startIndex); } else { currentNode.addChild(childNode, startIndex); } } var replaceEntitiesValue = function(val, tagName, jPath) { if (val.indexOf("&") === -1) { return val; } const entityConfig = this.options.processEntities; if (!entityConfig.enabled) { return val; } if (entityConfig.allowedTags) { if (!entityConfig.allowedTags.includes(tagName)) { return val; } } if (entityConfig.tagFilter) { if (