@middy/http-multipart-body-parser 3.0.0-alpha.7 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.cjs +3 -0
  2. package/index.js +1 -1
  3. package/package.json +14 -7
package/index.cjs ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _busboy=_interopRequireDefault(require("busboy"));var _util=require("@middy/util");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}const mimePattern=/^multipart\/form-data(;.*)?$/;const fieldnamePattern=/(.+)\[(.*)]$/;const defaults={busboy:{}};const httpMultipartBodyParserMiddleware=(opts={})=>{const options={...defaults,...opts};const httpMultipartBodyParserMiddlewareBefore=async request=>{const{headers}=request.event;const contentType=headers["Content-Type"]??headers["content-type"];if(!mimePattern.test(contentType))return;return parseMultipartData(request.event,options.busboy).then(multipartData=>{request.event.body=multipartData}).catch(cause=>{const error=(0,_util).createError(422,"Invalid or malformed multipart/form-data was provided");error.cause=cause;throw error})};return{before:httpMultipartBodyParserMiddlewareBefore}};const parseMultipartData=(event,options)=>{const multipartData={};const busboy=(0,_busboy).default({...options,headers:{"content-type":event.headers["Content-Type"]??event.headers["content-type"]}});return new Promise((resolve,reject)=>{busboy.on("file",(fieldname,file,filename,encoding,mimetype)=>{const attachment={filename,mimetype,encoding};const chunks=[];file.on("data",data=>{chunks.push(data)});file.on("end",()=>{attachment.truncated=file.truncated;attachment.content=Buffer.concat(chunks);if(!multipartData[fieldname]){multipartData[fieldname]=attachment}else{const current=multipartData[fieldname];multipartData[fieldname]=[attachment].concat(current)}})}).on("field",(fieldname,value)=>{const matches=fieldname.match(fieldnamePattern);if(!matches){multipartData[fieldname]=value}else{if(!multipartData[matches[1]]){multipartData[matches[1]]=[]}multipartData[matches[1]].push(value)}}).on("close",()=>resolve(multipartData)).on("error",e=>reject(e));busboy.write(event.body,event.isBase64Encoded?"base64":"utf8");busboy.end()})};var _default=httpMultipartBodyParserMiddleware;exports.default=_default
2
+
3
+ //# sourceMappingURL=index.cjs.map
package/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import BusBoy from'busboy';import{createError}from'@middy/util';const mimePattern=/^multipart\/form-data(;.*)?$/;const fieldnamePattern=/(.+)\[(.*)]$/;const defaults={busboy:{}};const httpMultipartBodyParserMiddleware=(opts={})=>{const options={...defaults,...opts};const httpMultipartBodyParserMiddlewareBefore=async request=>{const{headers}=request.event;const contentType=headers['Content-Type']??headers['content-type'];if(!mimePattern.test(contentType))return;return parseMultipartData(request.event,options.busboy).then(multipartData=>{request.event.body=multipartData}).catch(cause=>{const error=createError(422,'Invalid or malformed multipart/form-data was provided');error.cause=cause;throw error})};return{before:httpMultipartBodyParserMiddlewareBefore}};const parseMultipartData=(event,options)=>{const multipartData={};const busboy=BusBoy({...options,headers:{'content-type':event.headers['Content-Type']??event.headers['content-type']}});return new Promise((resolve,reject)=>{busboy.on('file',(fieldname,file,filename,encoding,mimetype)=>{const attachment={filename,mimetype,encoding};const chunks=[];file.on('data',data=>{chunks.push(data)});file.on('end',()=>{attachment.truncated=file.truncated;attachment.content=Buffer.concat(chunks);if(!multipartData[fieldname]){multipartData[fieldname]=attachment}else{const current=multipartData[fieldname];multipartData[fieldname]=[attachment].concat(current)}})}).on('field',(fieldname,value)=>{const matches=fieldname.match(fieldnamePattern);if(!matches){multipartData[fieldname]=value}else{if(!multipartData[matches[1]]){multipartData[matches[1]]=[]}multipartData[matches[1]].push(value)}}).on('close',()=>resolve(multipartData)).on('error',e=>reject(e));busboy.write(event.body,event.isBase64Encoded?'base64':'utf8');busboy.end()})};export default httpMultipartBodyParserMiddleware
1
+ import BusBoy from"busboy";import{createError}from"@middy/util";const mimePattern=/^multipart\/form-data(;.*)?$/;const fieldnamePattern=/(.+)\[(.*)]$/;const defaults={busboy:{}};const httpMultipartBodyParserMiddleware=(opts={})=>{const options={...defaults,...opts};const httpMultipartBodyParserMiddlewareBefore=async request=>{const{headers}=request.event;const contentType=headers["Content-Type"]??headers["content-type"];if(!mimePattern.test(contentType))return;return parseMultipartData(request.event,options.busboy).then(multipartData=>{request.event.body=multipartData}).catch(cause=>{const error=createError(422,"Invalid or malformed multipart/form-data was provided");error.cause=cause;throw error})};return{before:httpMultipartBodyParserMiddlewareBefore}};const parseMultipartData=(event,options)=>{const multipartData={};const busboy=BusBoy({...options,headers:{"content-type":event.headers["Content-Type"]??event.headers["content-type"]}});return new Promise((resolve,reject)=>{busboy.on("file",(fieldname,file,filename,encoding,mimetype)=>{const attachment={filename,mimetype,encoding};const chunks=[];file.on("data",data=>{chunks.push(data)});file.on("end",()=>{attachment.truncated=file.truncated;attachment.content=Buffer.concat(chunks);if(!multipartData[fieldname]){multipartData[fieldname]=attachment}else{const current=multipartData[fieldname];multipartData[fieldname]=[attachment].concat(current)}})}).on("field",(fieldname,value)=>{const matches=fieldname.match(fieldnamePattern);if(!matches){multipartData[fieldname]=value}else{if(!multipartData[matches[1]]){multipartData[matches[1]]=[]}multipartData[matches[1]].push(value)}}).on("close",()=>resolve(multipartData)).on("error",e=>reject(e));busboy.write(event.body,event.isBase64Encoded?"base64":"utf8");busboy.end()})};export default httpMultipartBodyParserMiddleware
2
2
 
3
3
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-multipart-body-parser",
3
- "version": "3.0.0-alpha.7",
3
+ "version": "3.0.1",
4
4
  "description": "Http event normalizer middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -10,10 +10,17 @@
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "exports": "./index.js",
13
+ "exports": {
14
+ ".": {
15
+ "import": "./index.js",
16
+ "require": "./index.cjs",
17
+ "types": "./index.d.ts"
18
+ }
19
+ },
14
20
  "types": "index.d.ts",
15
21
  "files": [
16
22
  "index.js",
23
+ "index.cjs",
17
24
  "index.d.ts"
18
25
  ],
19
26
  "scripts": {
@@ -46,13 +53,13 @@
46
53
  "bugs": {
47
54
  "url": "https://github.com/middyjs/middy/issues"
48
55
  },
49
- "homepage": "https://github.com/middyjs/middy#readme",
56
+ "homepage": "https://middy.js.org",
50
57
  "dependencies": {
51
- "@middy/util": "^3.0.0-alpha.7",
52
- "busboy": "1.4.0"
58
+ "@middy/util": "^3.0.1",
59
+ "busboy": "1.6.0"
53
60
  },
54
61
  "devDependencies": {
55
- "@middy/core": "^3.0.0-alpha.7"
62
+ "@middy/core": "^3.0.1"
56
63
  },
57
- "gitHead": "5cef39ebe49c201f97d71bb0680004de4b82cb91"
64
+ "gitHead": "797455e2c2be445867bc03597e0a2d5b0560c9de"
58
65
  }