{"version":3,"sources":["jsdelivr-header.js","/npm/@middy/http-json-body-parser@6.3.1/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,snqBCJA,MAAM,EAAc,mCAEd,GAAW,CAChB,aAAS,EACT,yBAAyB,GAGpB,GAA+B,CAAC,EAAO,MAC5C,MAAM,EAAU,IAAK,MAAa,GAsClC,MAAO,CACN,OAtC0C,MAAO,IACjD,MAAM,QAAE,EAAO,KAAE,GAAS,EAAQ,MAC5B,EAAc,IAAU,iBAAmB,IAAU,gBAE3D,IAAK,EAAY,KAAK,GAAc,CACnC,GAAI,EAAQ,wBACX,OAED,MAAM,EAAY,IAAK,yBAA0B,CAChD,MAAO,CAAE,QAAS,+BAAgC,KAAM,IAE5D,CAEE,QAAoB,IAAT,EACV,MAAM,EAAY,IAAK,yCAA0C,CAChE,MAAO,CAAE,QAAS,+BAAgC,KAAM,KAI1D,IACC,MAAM,EAAO,EAAQ,MAAM,gBACxB,EAAO,KAAK,EAAM,UAAU,WAC5B,EAEH,EAAQ,MAAM,KAAO,KAAK,MAAM,EAAM,EAAQ,QACjD,CAAI,MAAO,GAER,MAAM,EAAY,IAAK,yCAA0C,CAChE,MAAO,CACN,QAAS,+BACT,KAAM,EACN,QAAS,EAAI,UAGlB,GAKE,S","file":"/npm/@middy/http-json-body-parser@6.3.1/index.js/+esm","sourceRoot":"","sourcesContent":["/**\n * Bundled by jsDelivr using Rollup v2.79.2 and Terser v5.39.0.\n * Original file: /npm/@middy/http-json-body-parser@6.3.1/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { createError } from \"@middy/util\";\n\nconst mimePattern = /^application\\/(.+\\+)?json($|;.+)/;\n\nconst defaults = {\n\treviver: undefined,\n\tdisableContentTypeError: false,\n};\n\nconst httpJsonBodyParserMiddleware = (opts = {}) => {\n\tconst options = { ...defaults, ...opts };\n\tconst httpJsonBodyParserMiddlewareBefore = async (request) => {\n\t\tconst { headers, body } = request.event;\n\t\tconst contentType = headers?.[\"content-type\"] ?? headers?.[\"Content-Type\"];\n\n\t\tif (!mimePattern.test(contentType)) {\n\t\t\tif (options.disableContentTypeError) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow createError(415, \"Unsupported Media Type\", {\n\t\t\t\tcause: { package: \"@middy/http-json-body-parser\", data: contentType },\n\t\t\t});\n\t\t}\n\n\t\tif (typeof body === \"undefined\") {\n\t\t\tthrow createError(415, \"Invalid or malformed JSON was provided\", {\n\t\t\t\tcause: { package: \"@middy/http-json-body-parser\", data: body },\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst data = request.event.isBase64Encoded\n\t\t\t\t? Buffer.from(body, \"base64\").toString()\n\t\t\t\t: body;\n\n\t\t\trequest.event.body = JSON.parse(data, options.reviver);\n\t\t} catch (err) {\n\t\t\t// UnprocessableEntity\n\t\t\tthrow createError(415, \"Invalid or malformed JSON was provided\", {\n\t\t\t\tcause: {\n\t\t\t\t\tpackage: \"@middy/http-json-body-parser\",\n\t\t\t\t\tdata: body,\n\t\t\t\t\tmessage: err.message,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t};\n\n\treturn {\n\t\tbefore: httpJsonBodyParserMiddlewareBefore,\n\t};\n};\nexport default httpJsonBodyParserMiddleware;\n"]}