mailgun.js
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -5,2 +5,9 @@ # Changelog | ||
### [4.0.1](https://github.com/mailgun/mailgun.js/compare/v4.0.0...v4.0.1) (2021-11-25) | ||
### Bug Fixes | ||
* Fixes handling of mime messages ([#213](https://github.com/mailgun/mailgun.js/issues/213)) ([ad43490](https://github.com/mailgun/mailgun.js/commits/ad43490a562b95cb77e38cb66f71ef13a4da8331)) | ||
## [4.0.0](https://github.com/mailgun/mailgun.js/compare/v3.7.3...v4.0.0) (2021-11-18) | ||
@@ -7,0 +14,0 @@ |
@@ -11,3 +11,3 @@ import NodeFormData from 'form-data'; | ||
private headers; | ||
private formData; | ||
private FormDataConstructor; | ||
constructor(options: RequestOptions, formData: InputFormData); | ||
@@ -24,2 +24,5 @@ request(method: string, url: string, inputOptions?: any): Promise<APIResponse>; | ||
createFormData(data: any): NodeFormData | FormData; | ||
private addMimeDataToFD; | ||
private addFilesToFD; | ||
private addCommonPropertyToFD; | ||
put(url: string, data: any, options?: any): Promise<APIResponse>; | ||
@@ -26,0 +29,0 @@ patch(url: string, data: any, options?: any): Promise<APIResponse>; |
@@ -5,2 +5,2 @@ /*! MIT License © Sindre Sorhus */ | ||
/*! mailgun.js v3.7.3 */ | ||
/*! mailgun.js v4.0.0 */ |
@@ -7,2 +7,2 @@ /*! MIT License © Sindre Sorhus */ | ||
/*! mailgun.js v3.7.3 */ | ||
/*! mailgun.js v4.0.0 */ |
@@ -53,3 +53,3 @@ import NodeFormData from 'form-data'; | ||
private headers: any; | ||
private formData: InputFormData; | ||
private FormDataConstructor: InputFormData; | ||
@@ -62,3 +62,3 @@ constructor(options: RequestOptions, formData: InputFormData) { | ||
this.headers = options.headers || {}; | ||
this.formData = formData; | ||
this.FormDataConstructor = formData; | ||
} | ||
@@ -171,45 +171,78 @@ | ||
createFormData(data: any): NodeFormData | FormData { | ||
const formData: NodeFormData | FormData = Object.keys(data) | ||
.filter(function (key) { return data[key]; }) | ||
.reduce((formDataAcc: NodeFormData | FormData, key) => { | ||
const fileKeys = ['attachment', 'inline', 'file']; | ||
if (fileKeys.includes(key)) { | ||
this.addFilesToFD(key, data[key], formDataAcc); | ||
return formDataAcc; | ||
} | ||
if (key === 'message') { // mime message | ||
this.addMimeDataToFD(key, data[key], formDataAcc); | ||
return formDataAcc; | ||
} | ||
this.addCommonPropertyToFD(key, data[key], formDataAcc); | ||
return formDataAcc; | ||
}, new this.FormDataConstructor()); | ||
return formData; | ||
} | ||
private addMimeDataToFD( | ||
key: string, | ||
data: Buffer | Blob, | ||
formDataInstance: NodeFormData | FormData | ||
): void { | ||
if (isNodeFormData(formDataInstance)) { | ||
if (Buffer.isBuffer(data)) { | ||
formDataInstance.append(key, data, { filename: 'MimeMessage' }); | ||
} | ||
} else { | ||
formDataInstance.append(key, data as Blob, 'MimeMessage'); | ||
} | ||
} | ||
private addFilesToFD( | ||
propertyName: string, | ||
value: any, | ||
formDataInstance: NodeFormData | FormData | ||
): void { | ||
const appendFileToFD = ( | ||
key: string, | ||
obj: any, | ||
formDataInstance: NodeFormData | FormData | ||
formData: NodeFormData | FormData | ||
): void => { | ||
const isStreamData = isStream(obj); | ||
const objData = isStreamData ? obj : obj.data; | ||
// getAttachmentOptions should be called with obj parameter to prevent loosing filename | ||
const options = getAttachmentOptions(obj); | ||
if (isNodeFormData(formDataInstance)) { | ||
formDataInstance.append(key, objData, options); | ||
if (isNodeFormData(formData)) { | ||
formData.append(key, objData, options); | ||
return; | ||
} | ||
formDataInstance.append(key, objData, options.filename); | ||
formData.append(key, objData, options.filename); | ||
}; | ||
const formData: NodeFormData | FormData = Object.keys(data) | ||
.filter(function (key) { return data[key]; }) | ||
.reduce((formDataAcc: NodeFormData | FormData, key) => { | ||
if (key === 'attachment' || key === 'inline' || key === 'file') { | ||
const obj = data[key]; | ||
if (Array.isArray(value)) { | ||
value.forEach(function (item) { | ||
appendFileToFD(propertyName, item, formDataInstance); | ||
}); | ||
} else { | ||
appendFileToFD(propertyName, value, formDataInstance); | ||
} | ||
} | ||
if (Array.isArray(obj)) { | ||
obj.forEach(function (item) { | ||
appendFileToFD(key, item, formDataAcc); | ||
}); | ||
} else { | ||
appendFileToFD(key, obj, formDataAcc); | ||
} | ||
return formDataAcc; | ||
} | ||
if (Array.isArray(data[key])) { | ||
data[key].forEach(function (item: any) { | ||
formDataAcc.append(key, item); | ||
}); | ||
} else if (data[key] != null) { | ||
formDataAcc.append(key, data[key]); | ||
} | ||
return formDataAcc; | ||
// eslint-disable-next-line new-cap | ||
}, new this.formData()); | ||
return formData; | ||
private addCommonPropertyToFD( | ||
key: string, | ||
value: any, | ||
formDataAcc: NodeFormData | FormData | ||
): void { | ||
if (Array.isArray(value)) { | ||
value.forEach(function (item: any) { | ||
formDataAcc.append(key, item); | ||
}); | ||
} else if (value != null) { | ||
formDataAcc.append(key, value); | ||
} | ||
} | ||
@@ -216,0 +249,0 @@ |
{ | ||
"name": "mailgun.js", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"main": "dist/mailgun.node.js", | ||
@@ -108,5 +108,6 @@ "browser": "dist/mailgun.web.js", | ||
"scripts": { | ||
"prerelease": "npm test && webpack --config ./webpack/webpack.release.config.js --progress --color && git add -A dist" | ||
"prerelease": "npm test && webpack --config ./webpack/webpack.release.config.js --progress --color && git add -A dist", | ||
"posttag": "git push && git push --tags && rm -rf build" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2287348
5497